go-dsp: github.com/mjibson/go-dsp/fft

## package fft

`import "github.com/mjibson/go-dsp/fft"`

Package fft provides forward and inverse fast Fourier transform functions.

### func Convolve¶Uses

`func Convolve(x, y []complex128) []complex128`

Convolve returns the convolution of x ∗ y.

`func EnsureRadix2Factors(input_len int)`

EnsureRadix2Factors ensures that all radix 2 factors are computed for inputs of length input_len. This is used to precompute needed factors for known sizes. Generally should only be used for benchmarks.

### func FFT¶Uses

`func FFT(x []complex128) []complex128`

FFT returns the forward FFT of the complex-valued slice.

### func FFT2¶Uses

`func FFT2(x [][]complex128) [][]complex128`

FFT2 returns the 2-dimensional, forward FFT of the complex-valued matrix.

### func FFT2Real¶Uses

`func FFT2Real(x [][]float64) [][]complex128`

FFT2Real returns the 2-dimensional, forward FFT of the real-valued matrix.

### func FFTN¶Uses

`func FFTN(m *dsputils.Matrix) *dsputils.Matrix`

FFTN returns the forward FFT of the matrix m, computed in all N dimensions.

### func FFTReal¶Uses

`func FFTReal(x []float64) []complex128`

FFTReal returns the forward FFT of the real-valued slice.

This example is adapted from Richard Lyon's "Understanding Digital Signal Processing," section 3.1.1.

Code:

```numSamples := 8

// Equation 3-10.
x := func(n int) float64 {
wave0 := math.Sin(2.0 * math.Pi * float64(n) / 8.0)
wave1 := 0.5 * math.Sin(2*math.Pi*float64(n)/4.0+3.0*math.Pi/4.0)
return wave0 + wave1
}

// Discretize our function by sampling at 8 points.
a := make([]float64, numSamples)
for i := 0; i < numSamples; i++ {
a[i] = x(i)
}

X := FFTReal(a)

// Print the magnitude and phase at each frequency.
for i := 0; i < numSamples; i++ {
r, θ := cmplx.Polar(X[i])
θ *= 360.0 / (2 * math.Pi)
if dsputils.Float64Equal(r, 0) {
θ = 0 // (When the magnitude is close to 0, the angle is meaningless)
}
fmt.Printf("X(%d) = %.1f ∠ %.1f°\n", i, r, θ)
}```

Output:

```X(0) = 0.0 ∠ 0.0°
X(1) = 4.0 ∠ -90.0°
X(2) = 2.0 ∠ 45.0°
X(3) = 0.0 ∠ 0.0°
X(4) = 0.0 ∠ 0.0°
X(5) = 0.0 ∠ 0.0°
X(6) = 2.0 ∠ -45.0°
X(7) = 4.0 ∠ 90.0°
```

### func IFFT¶Uses

`func IFFT(x []complex128) []complex128`

IFFT returns the inverse FFT of the complex-valued slice.

### func IFFT2¶Uses

`func IFFT2(x [][]complex128) [][]complex128`

IFFT2 returns the 2-dimensional, inverse FFT of the complex-valued matrix.

### func IFFT2Real¶Uses

`func IFFT2Real(x [][]float64) [][]complex128`

IFFT2Real returns the 2-dimensional, inverse FFT of the real-valued matrix.

### func IFFTN¶Uses

`func IFFTN(m *dsputils.Matrix) *dsputils.Matrix`

IFFTN returns the forward FFT of the matrix m, computed in all N dimensions.

### func IFFTReal¶Uses

`func IFFTReal(x []float64) []complex128`

IFFTReal returns the inverse FFT of the real-valued slice.

### func SetWorkerPoolSize¶Uses

`func SetWorkerPoolSize(n int)`

SetWorkerPoolSize sets the number of workers during FFT computation on multicore systems. If n is 0 (the default), then GOMAXPROCS workers will be created.

Package fft imports 4 packages (graph) and is imported by 64 packages. Updated 2020-01-26. Refresh now. Tools for package owners.