packages

signal::fft::plan

On this page

Plan: a length's passes and twiddles, built once and reused.

Structs

PlanSource

pub struct Plan

A 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.

nabi
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
  • pub fn new(n: usize) throws (SignalError) -> Plan§

    Source

    The plan for length n (at least 1).

  • pub fn len(self) -> usize§

    Source

    The length this plan transforms.

  • pub fn is_bluestein(self) -> bool§

    Source

    true when 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; see next_fast_len.

  • pub fn forward_split(self, re: List<f64>, im: List<f64>, norm: Norm = Norm::Backward) throws (SignalError)§

    Source

    The forward DFT X_k = sum_j x_j exp(-2 pi i j k / n) of the split parts re / im in place, scaled by norm. Both lists hold exactly len() items. The fastest way to run a plan: no conversion and no allocation.

  • pub fn inverse_split(self, re: List<f64>, im: List<f64>, norm: Norm = Norm::Backward) throws (SignalError)§

    Source

    The inverse DFT x_j = sum_k X_k exp(2 pi i j k / n) (divided by n under Norm::Backward) of re / im in place.

  • pub fn forward(self, x: Vector<Complex<f64>>, norm: Norm = Norm::Backward) throws (SignalError) -> Vector<Complex<f64>>§

    Source

    The forward DFT of x, which has len() samples.

  • pub fn inverse(self, x: Vector<Complex<f64>>, norm: Norm = Norm::Backward) throws (SignalError) -> Vector<Complex<f64>>§

    Source

    The inverse DFT of x, which has len() samples.

Enums

NormSource

pub enum Norm

How 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.

nabi
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).

nabi
println(signal::fft::next_fast_len(1009)); // 1024
println(signal::fft::next_fast_len(1000)); // 1000