signal::fft::plan
Plan: a length's passes and twiddles, built once and reused.
Structs
PlanSource
pub struct PlanA complex FFT of one length with its twiddles computed once: build
it with Plan::new(n) and run it on many signals. Any length works:
lengths whose prime factors are all at most 61 use a mixed-radix
Stockham FFT (radix 4, 2, 3, 5 and direct odd-prime butterflies),
others Bluestein's chirp-z algorithm over a power of two. Either way
the cost is O(n log n) and the error about eps * log2(n) relative
to the signal's norm.
A plan holds scratch buffers, so one plan serves one thread at a
time (it is not Sync); give each thread its own.
use signal::fft::Plan;
use core::array::{Array, Vector};
use core::num::Complex;
let p = try Plan::new(8);
let x: Vector<Complex<f64>> = Array::full([8], 1.0 + 0i);
let y = try p.forward(x);
println(y[0]); // 8+0i
Sourcepub fn new(§n: usize) throws (SignalError) -> Plan The plan for length
n(at least 1).The length this plan transforms.
truewhen this length uses Bluestein's algorithm (it has a prime factor above 61) and so runs a few times slower than a nearby smooth length; seenext_fast_len.
Sourcepub fn forward_split(§self, re: List<f64>, im: List<f64>, norm: Norm = Norm::Backward) throws (SignalError) The forward DFT
X_k = sum_j x_j exp(-2 pi i j k / n)of the split partsre/imin place, scaled bynorm. Both lists hold exactlylen()items. The fastest way to run a plan: no conversion and no allocation.
Sourcepub fn inverse_split(§self, re: List<f64>, im: List<f64>, norm: Norm = Norm::Backward) throws (SignalError) The inverse DFT
x_j = sum_k X_k exp(2 pi i j k / n)(divided bynunderNorm::Backward) ofre/imin place.
Sourcepub fn forward(§self, x: Vector<Complex<f64>>, norm: Norm = Norm::Backward) throws (SignalError) -> Vector<Complex<f64>> The forward DFT of
x, which haslen()samples.
Sourcepub fn inverse(§self, x: Vector<Complex<f64>>, norm: Norm = Norm::Backward) throws (SignalError) -> Vector<Complex<f64>> The inverse DFT of
x, which haslen()samples.
Enums
NormSource
pub enum NormHow a transform is scaled: Backward (the default, as NumPy)
leaves the forward transform unscaled and divides the inverse by
n; Ortho divides both by sqrt(n), so the pair is unitary;
Forward divides the forward transform by n.
use signal::fft::{fft, Norm};
use core::array::Vector;
let x: Vector<f64> = [1, 1, 1, 1];
println(signal::real(try fft(x, norm: Norm::Ortho))); // [2.0, 0.0, 0.0, 0.0]
Functions
next_fast_lenSource
pub fn next_fast_len(n: usize) -> usize The smallest m >= n whose prime factors are 2, 3 and 5 only: the
fastest lengths to pad to (for convolution, say).
println(signal::fft::next_fast_len(1009)); // 1024
println(signal::fft::next_fast_len(1000)); // 1000