Skip to main content

lib_jsl_ffts/
fft_engine_trait.rs

1//! The interface shared by the one-dimensional FFT engines: plan once for a size, scaling,
2//! direction and input ordering, then execute repeatedly.
3//!
4//! See the book entry [Fast Fourier transforms](https://jwkunz.github.io/lib_jsl/book/fft/index.html#two-crates).
5
6/// The sign of the exponent: `Forward` computes `X_k = Σ x_n e^{−2πi kn/N}`, `Inverse` uses `e^{+2πi kn/N}`.
7#[derive(Clone,Copy,Debug)]
8pub enum FftDirection {
9    Forward, // exp(-2*pi*i*k*n/N)
10    Inverse, // exp(2*pi*i*k*n/N)
11}
12
13/// The factor applied to the output: none, `1/√N` (the unitary transform) or `1/N`.
14#[derive(Clone,Copy,Debug)]
15pub enum FftScaleFactor {
16    None,
17    SqrtN,
18    N,
19}
20
21/// The order of the input samples (the output is always in natural order).
22#[derive(Clone,Copy,Debug)]
23pub enum FftOrdering {
24    Standard, // k = 0, 1, ..., N-1
25    BitReversed,  // input samples arrive in bit-reversed index order (output is in natural order)
26}
27
28
29use num_complex::Complex;
30
31use lib_jsl_core::{ErrorsJSL};
32/// A planned one-dimensional complex FFT.
33pub trait FftEngine1D {
34    fn execute(&mut self, input: &[Complex<f64>]) -> Result<Vec<Complex<f64>>, ErrorsJSL>;
35    fn plan(&mut self, size: usize, scale: FftScaleFactor, direction: FftDirection, ordering: FftOrdering) -> Result<(), ErrorsJSL>;
36    fn get_size(&self) -> usize;
37    fn get_scale_factor(&self) -> FftScaleFactor;
38    fn get_direction(&self) -> FftDirection;
39    fn get_ordering(&self) -> FftOrdering;
40}