Documentation ¶
Overview ¶
Package gofft provides a fast discrete Fourier transformation algorithm.
Implemented is the 1-dimensional DFT of complex input data for with input lengths which are powers of 2.
The algorithm is non-recursive, works in-place overwriting the input array, and requires O(1) additional space.
Index ¶
- func Complex128ToFloat64Array(x []complex128) []float64
- func Convolve(x, y []complex128) ([]complex128, error)
- func FFT(x []complex128) error
- func FastConvolve(x, y []complex128) error
- func FastMultiConvolve(X []complex128, n int, multithread bool) error
- func Float64ToComplex128Array(x []float64) []complex128
- func IFFT(x []complex128) error
- func IsPow2(N int) bool
- func MultiConvolve(X ...[]complex128) ([]complex128, error)
- func NextPow2(N int) int
- func Prepare(N int) errordeprecated
- func RoundFloat64Array(x []float64)
- func ZeroPad(x []complex128, N int) []complex128
- func ZeroPadToNextPow2(x []complex128) []complex128
- type InputSizeError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Complex128ToFloat64Array ¶
func Complex128ToFloat64Array(x []complex128) []float64
Complex128ToFloat64Array converts a complex128 array to the equivalent float64 array taking only the real part.
func Convolve ¶
func Convolve(x, y []complex128) ([]complex128, error)
Convolve computes the discrete convolution of x and y using FFT. Pads x and y to the next power of 2 from len(x)+len(y)-1
func FFT ¶
func FFT(x []complex128) error
FFT implements the fast Fourier transform. This is done in-place (modifying the input array). Requires O(1) additional memory. len(x) must be a perfect power of 2, otherwise this will return an error.
func FastConvolve ¶
func FastConvolve(x, y []complex128) error
FastConvolve computes the discrete convolution of x and y using FFT and stores the result in x, while erasing y (setting it to 0s). Since this does no allocations, x and y are assumed to already be 0-padded for at least half their length.
func FastMultiConvolve ¶
func FastMultiConvolve(X []complex128, n int, multithread bool) error
FastMultiConvolve computes the discrete convolution of many arrays using a hierarchical FFT algorithm, and stores the result in the first section of the input, writing 0s to the remainder of the input This does no allocations, so the arrays must first be 0-padded out to the next power of 2 from sum of the lengths of the longest two arrays. Additionally, the number of arrays must be a power of 2 X is the concatenated array of arrays, of length N (n*m) n is the length of the 0-padded arrays. multithread tells the algorithm to use goroutines, which can slow things down for small N. Takes O(N*log(N)^2) run time and O(1) additional space.
func Float64ToComplex128Array ¶
func Float64ToComplex128Array(x []float64) []complex128
Float64ToComplex128Array converts a float64 array to the equivalent complex128 array using an imaginary part of 0.
func IFFT ¶
func IFFT(x []complex128) error
IFFT implements the inverse fast Fourier transform. This is done in-place (modifying the input array). Requires O(1) additional memory. len(x) must be a perfect power of 2, otherwise this will return an error.
func IsPow2 ¶
IsPow2 returns true if N is a perfect power of 2 (1, 2, 4, 8, ...) and false otherwise. Algorithm from: https://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2
func MultiConvolve ¶
func MultiConvolve(X ...[]complex128) ([]complex128, error)
MultiConvolve computes the discrete convolution of many arrays using a hierarchical FFT algorithm that successfully builds up larger convolutions. This requires allocating up to 4*N extra memory for appropriate 0-padding where N=sum(len(x) for x in X). Takes O(N*log(N)^2) run time and O(N) additional space.
This is much slower and takes many more allocations than FastMultiConvolve below, but has a smart planner that handles disproportionate array sizes very well. If all your arrays are the same length, FastMultiConvolve will be much faster.
func RoundFloat64Array ¶
func RoundFloat64Array(x []float64)
RoundFloat64Array calls math.Round on each entry in x, changing the array in-place
func ZeroPad ¶
func ZeroPad(x []complex128, N int) []complex128
ZeroPad pads x with 0s at the end into a new array of length N. This does not alter x, and creates an entirely new array. This should only be used as a convience function, and isn't meant for performance. You should call this as few times as possible since it does potentially large allocations.
func ZeroPadToNextPow2 ¶
func ZeroPadToNextPow2(x []complex128) []complex128
ZeroPadToNextPow2 pads x with 0s at the end into a new array of length 2^N >= len(x) This does not alter x, and creates an entirely new array. This should only be used as a convience function, and isn't meant for performance. You should call this as few times as possible since it does potentially large allocations.
Types ¶
type InputSizeError ¶ added in v1.2.1
InputSizeError represents an error when an input vector's size is not a power of 2.
func (*InputSizeError) Error ¶ added in v1.2.1
func (e *InputSizeError) Error() string