TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Nonanti/mathcore/llms.txt
Use this file to discover all available pages before exploring further.
mathcore::transforms module provides frequency-domain signal processing through the FFT struct. It exposes a forward FFT (Cooley-Tukey, with a rustfft backend when the fft feature flag is enabled), an always-available O(n²) DFT, an inverse FFT, a 2-D FFT for image processing, power-spectrum computation, and FFT-accelerated convolution. The sparse submodule additionally provides a Compressed Sparse Row matrix for efficient sparse linear-algebra operations.
All FFT and DFT methods operate on Complex64 values from the num-complex crate.
Feature flag: fft
When the fft Cargo feature is enabled, the fft method delegates to a pre-planned rustfft::FftPlanner for high-performance FFTs on arbitrary-length inputs.
fft feature, fft falls back to the built-in recursive Cooley-Tukey implementation (power-of-two sizes) or the O(n²) DFT for non-power-of-two lengths. dft is always available regardless of the feature flag.
pub struct FFT
A zero-sized unit struct that namespaces all transform operations. No instance is required.
fft
Computes the Discrete Fourier Transform using the Cooley-Tukey algorithm. With the fft feature enabled the computation is delegated to a rustfft forward planner. Without the feature, the built-in recursive split-radix implementation is used for power-of-two lengths; non-power-of-two inputs automatically fall back to dft.
The output vector has the same length as the input. Output element k is:
The input signal in the time domain as a slice of complex values. Real-only signals should be passed with imaginary parts set to
0.0. Inputs of length 0 or 1 are returned unchanged.Vec<Complex64> of the same length as input, containing the frequency-domain representation. The DC component is at index 0.
dft
Computes the Discrete Fourier Transform using a direct O(n²) double-loop algorithm. Always available regardless of the fft feature flag. Useful for reference, small inputs, or non-power-of-two lengths where the fast path is unavailable.
The input signal as a complex slice. There is no length restriction; any non-negative length is accepted.
Vec<Complex64> of the same length, containing frequency coefficients identical in definition to the fft output.
ifft
Computes the Inverse Fast Fourier Transform by conjugating the input, calling fft, then conjugating and scaling the output by 1/n.
The frequency-domain signal (e.g., output of
fft). Must have the same length as the original time-domain signal.Vec<Complex64> of the same length, approximating the original time-domain signal.
fft2d
Performs a 2-D FFT on a rectangular grid of complex values. The transform is applied first along each row, then along each column of the intermediate result (separable row-column decomposition).
A rectangular grid represented as a slice of rows, where each row is a
Vec<Complex64> of equal length. An empty input returns an empty output immediately.Vec<Vec<Complex64>> of the same dimensions containing the 2-D frequency coefficients.
power_spectrum
Computes the power spectrum of a real-valued signal. The signal is first wrapped into Complex64 values (imaginary part 0), FFT-transformed, and then the squared magnitude |X[k]|² is computed for each bin.
The real-valued time-domain signal. The output has the same length.
Vec<f64> of power values at each frequency bin, where result[k] = re(X[k])² + im(X[k])².
convolve
Convolves two real-valued sequences using FFT-based fast convolution (O(n log n)). Both inputs are zero-padded to the next power of two, pointwise-multiplied in the frequency domain, and then transformed back.
First real-valued sequence.
Second real-valued sequence (filter kernel).
Vec<f64> of length a.len() + b.len() - 1 containing the linear convolution of a and b.
