fft

package
v0.0.0-...-11479a3 Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: ISC Imports: 4 Imported by: 0

Documentation

Overview

Package fft provides forward and inverse fast Fourier transform functions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convolve

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

Convolve returns the convolution of x ∗ y.

func EnsureRadix2Factors

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

func FFT(x []complex128) []complex128

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

func FFT2

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

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

func FFT2Real

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

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

func FFTN

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

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

func FFTReal

func FFTReal(x []float64) []complex128

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

Example

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

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

func IFFT(x []complex128) []complex128

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

func IFFT2

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

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

func IFFT2Real

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

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

func IFFTN

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

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

func IFFTReal

func IFFTReal(x []float64) []complex128

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

func SetWorkerPoolSize

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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