Skip to main content

Module fft

Module fft 

Source
Expand description

FFT plans with the NumPy conventions.

Fft wraps the forward and inverse plans of rustfft for one length: Fft::forward computes X_k = Σ_n x_n e^{-j2πkn/N} (unnormalised) and Fft::inverse x_n = (1/N) Σ_k X_k e^{+j2πkn/N}, the conventions of numpy.fft and of OptiCommPy. Plans are cached per thread by plan, so creating an Fft for a length already seen costs nothing, and the work space of the transforms is kept per thread next to them: a transform allocates nothing once its length has been seen. fftfreq and angular_frequencies give the frequency of every bin in the same order, fftshift reorders a spectrum by increasing frequency and centred_bin maps centred subcarriers to bins. The unitary transforms are fft_unitary_in_place and ifft_unitary_in_place.

§Examples

use comnum_math::fft::{fft, ifft, fftfreq};
use comnum_math::C64;
let x: Vec<C64> = (0..8).map(|n| C64::new(n as f64, 0.0)).collect();
let y = ifft(&fft(&x));
assert!(x.iter().zip(&y).all(|(a, b)| (a - b).norm() < 1e-12));
assert_eq!(fftfreq(4, 1.0), vec![0.0, 0.25, -0.5, -0.25]);

Structs§

Fft
Forward and inverse FFT plans of one length.

Functions§

angular_frequencies
Angular frequencies 2π f (rad/s) of the bins at the sampling rate fs.
centred_bin
The DFT bin of the i-th of k contiguous subcarriers centred on bin 0 (indices -k/2 … k/2 - 1, in increasing frequency) on a grid of n bins: (i - ⌊k/2⌋) mod n.
fft
Forward FFT of a slice (allocates the output).
fft_unitary_in_place
The unitary forward DFT in place, X_k = Σ_n x_n e^{-j2πkn/N} / √N (energy preserving).
fftfreq
Frequencies of the DFT bins for a sample spacing spacing_s (numpy.fft.fftfreq): [0, 1, …, ⌈N/2⌉-1, -⌊N/2⌋, …, -1] / (N d).
fftshift
Swap the two halves of a spectrum so that the zero frequency is in the middle (numpy.fft.fftshift): the bin (i + ⌊N/2⌋) mod N moves to i.
filter
Filter a periodic block by its frequency response: IFFT(FFT(x) · H), H one value per DFT bin in the order of fftfreq (a circular convolution).
ifft
Inverse FFT of a slice, divided by N (allocates the output).
ifft_unitary_in_place
The unitary inverse DFT in place, x_n = Σ_k X_k e^{+j2πkn/N} / √N.
plan
The (cached) plans of length n ≥ 1.