fft

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fft provides numpy.fft-semantics discrete Fourier transforms over numgo arrays, backed by an own FFT: mixed-radix Cooley-Tukey + Bluestein for large primes.

Semantics follow numpy.fft (pocketfft): the forward transform is A_k = Σ_j a_j·exp(-2πi·jk/n), the last axis is transformed by default, arbitrary (mixed-radix) transform lengths are supported, n == 0 means "use the axis length" (Go's zero value stands in for numpy's None) and n > 0 zero-pads or truncates, and norm follows numpy's backward/ortho/forward modes with factors applied per transformed axis over the padded length n. IRFFT-family results are returned as float64 (the imaginary part is zero by construction, matching numpy's real output dtype). FFTShift/IFFTShift return pure copies, never views.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FFT

func FFT[T numgo.Number](a *numgo.Array[T], n int, norm Norm, axes ...int) *numgo.Array[complex128]

FFT transforms a along one axis (default last). n == 0 uses the axis length; n > 0 zero-pads or truncates. Full-spectrum complex128 output.

func FFT2

func FFT2[T numgo.Number](a *numgo.Array[T], s []int, norm Norm) *numgo.Array[complex128]

FFT2 transforms the last two axes (numpy fft2's default (-2,-1)). s == nil or s[i] <= 0 uses the axis length; positive s[i] pads/truncates.

func FFTFreq

func FFTFreq(n int, d float64) *numgo.Array[float64]

FFTFreq returns n sample frequencies in cycles per unit of the sample spacing d: [0, 1, ..., n/2-1, -n/2, ..., -1] / (n*d).

func FFTN

func FFTN[T numgo.Number](a *numgo.Array[T], s []int, norm Norm, axes ...int) *numgo.Array[complex128]

FFTN transforms along the given axes (default: all axes). s aligns with axes: s == nil or s[i] <= 0 uses the axis length; positive s[i] zero-pads or truncates that axis.

func FFTShift

func FFTShift[T numgo.Number](a *numgo.Array[T], axes ...int) *numgo.Array[T]

FFTShift shifts the zero-frequency component to the center by rolling each listed axis (default: all) by n//2. The result is a pure copy.

func HFFT

func HFFT(a *numgo.Array[complex128], n int, norm Norm, axes ...int) *numgo.Array[float64]

HFFT is the inverse of IHFFT: a complex Hermitian half-spectrum in, real float64 output of length n (n == 0 means 2*(m-1)).

func IFFT

func IFFT[T numgo.Number](a *numgo.Array[T], n int, norm Norm, axes ...int) *numgo.Array[complex128]

IFFT is the inverse of FFT. n == 0 uses the axis length; n > 0 zero-pads or truncates the input.

func IFFT2

func IFFT2[T numgo.Number](a *numgo.Array[T], s []int, norm Norm) *numgo.Array[complex128]

IFFT2 is the two-dimensional inverse of FFT2 along the last two axes.

func IFFTN

func IFFTN[T numgo.Number](a *numgo.Array[T], s []int, norm Norm, axes ...int) *numgo.Array[complex128]

IFFTN is the inverse of FFTN with the same s/axes conventions.

func IFFTShift

func IFFTShift[T numgo.Number](a *numgo.Array[T], axes ...int) *numgo.Array[T]

IFFTShift is the inverse of FFTShift: it rolls each listed axis by -n/2. Identical to FFTShift for even-length axes. The result is a pure copy.

func IHFFT

func IHFFT[T numgo.Float](a *numgo.Array[T], n int, norm Norm, axes ...int) *numgo.Array[complex128]

IHFFT is the inverse of HFFT: real input, complex conjugated half-spectrum output of length n//2+1 (numpy's ihfft; the input must be real, as in numpy where complex input raises TypeError).

func IRFFT

func IRFFT(a *numgo.Array[complex128], n int, norm Norm, axes ...int) *numgo.Array[float64]

IRFFT inverts RFFT: complex half-spectrum input, real float64 output of length n (n == 0 means 2*(m-1) for input length m along the axis).

func IRFFT2

func IRFFT2(a *numgo.Array[complex128], s []int, norm Norm) *numgo.Array[float64]

IRFFT2 is the two-dimensional inverse of RFFT2; the result is a real float64 array.

func IRFFTN

func IRFFTN(a *numgo.Array[complex128], s []int, norm Norm, axes ...int) *numgo.Array[float64]

IRFFTN is the inverse of RFFTN; the last listed axis is the half-spectrum (default output length there is 2*(m-1)), the rest are full complex axes. The result is a real float64 array.

func RFFT

func RFFT[T numgo.Float](a *numgo.Array[T], n int, norm Norm, axes ...int) *numgo.Array[complex128]

RFFT is the FFT of real input along one axis, returning the non-negative frequency half-spectrum of length n//2+1 (including the Nyquist bin).

func RFFT2

func RFFT2[T numgo.Float](a *numgo.Array[T], s []int, norm Norm) *numgo.Array[complex128]

RFFT2 is the two-dimensional real FFT along the last two axes; the last output axis holds the half-spectrum n//2+1.

func RFFTFreq

func RFFTFreq(n int, d float64) *numgo.Array[float64]

RFFTFreq returns the non-negative frequencies of RFFT output: [0, 1, ..., n/2] / (n*d).

func RFFTN

func RFFTN[T numgo.Float](a *numgo.Array[T], s []int, norm Norm, axes ...int) *numgo.Array[complex128]

RFFTN is the n-dimensional real FFT: RFFT along the last listed axis, then FFT along the others. Like numpy, the real-input RFFT runs first so the remaining transforms operate on the complex half-spectrum.

Types

type Norm

type Norm int

Norm selects the normalization of a forward/backward transform pair, mirroring numpy.fft's norm argument. Backward (numpy's default) scales the forward transform by 1 and the inverse by 1/n; Forward is the mirror image; Ortho scales both by 1/√n. n is the resolved transform length, including any zero padding.

const (
	// Backward is numpy's default: 1 on the forward transform, 1/n on the inverse.
	Backward Norm = iota
	// Ortho scales both directions by 1/√n.
	Ortho
	// Forward scales the forward transform by 1/n and the inverse by 1.
	Forward
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL