Documentation
¶
Overview ¶
Package fft 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 ApplyWindow(x []complex128, window Window) []complex128
- func ApplyWindow64(x []complex64, window Window) []complex64
- func Complex64ToComplex128(data []complex64) []complex128
- func Complex128ToComplex64(data []complex128) []complex64
- func Complex128ToFloat64Array(x []complex128) []float64
- func Compute(x []complex64) error
- func Compute64(x []complex128) error
- func ComputeFramesOverlap(x []complex64, overlapRatio float32, fftSize int) ([]complex64, error)
- func Convolve(x, y []complex128) ([]complex128, error)
- func FastConvolve(x, y []complex128) error
- func FastMultiConvolve(X []complex128, n int, multithread bool) error
- func Float64ToComplex128Array(x []float64) []complex128
- func InvCompute(x []complex64) error
- func InvCompute64(x []complex128) error
- func IsPow2(N int) bool
- func MultiConvolve(X ...[]complex128) ([]complex128, error)
- func NextPow2(N int) int
- func PowerSpectrum(x []complex64) []float32
- func PowerSpectrumPrecision(x []complex128) []float64
- func Prepare(N int) errordeprecated
- func RoundFloat64Array(x []float64)
- func ZeroPad(x []complex128, N int) []complex128
- func ZeroPadToNextPow2(x []complex128) []complex128
- type InputSizeError
- type Window
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyWindow ¶
func ApplyWindow(x []complex128, window Window) []complex128
ApplyWindow applies the specified window function to the input data
func ApplyWindow64 ¶
ApplyWindow64 applies the specified window function to the input data
func Complex64ToComplex128 ¶
func Complex64ToComplex128(data []complex64) []complex128
Complex64ToComplex128 converts a slice of complex64 to complex128
func Complex128ToComplex64 ¶
func Complex128ToComplex64(data []complex128) []complex64
Complex128ToComplex64 converts a slice of complex128 to complex64
func Complex128ToFloat64Array ¶
func Complex128ToFloat64Array(x []complex128) []float64
Complex128ToFloat64Array converts a complex128 array to the equivalent float64 array taking only the real part.
func Compute ¶
Compute implements the fast Fourier transform. In Float32 Format 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 Compute64 ¶
func Compute64(x []complex128) error
Compute64 is the precision 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. WŒ„´‰ˇÁ¨∏”’/* Í˝˝ ÔÒÚÆ¸˛Ç◊ı˜Â*/
func ComputeFramesOverlap ¶
ComputeFramesOverlap computes windowed FFT frames with overlap and averaging - with moving, windowing, copying and averaging
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 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 InvCompute ¶
InvCompute mplements 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 InvCompute64 ¶
func InvCompute64(x []complex128) error
InvCompute64 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 PowerSpectrum ¶
PowerSpectrum computes the power spectrum of the FFT result
func PowerSpectrumPrecision ¶
func PowerSpectrumPrecision(x []complex128) []float64
PowerSpectrumPrecision computes the power spectrum of the FFT result
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 ¶
InputSizeError represents an error when an input vector's size is not a power of 2.
func (*InputSizeError) Error ¶
func (e *InputSizeError) Error() string