scirs2-fft
Fast Fourier Transform library for Rust, modeled after SciPy's fft module.
scirs2-fft provides a comprehensive suite of frequency-domain algorithms — FFT, RFFT, DCT/DST, STFT, NUFFT, sparse FFT, fractional FFT, wavelet packets, polyphase filter banks, and more — all in pure Rust using OxiFFT as the core FFT engine.
Installation
[]
= "0.3.0"
With parallel processing:
[]
= { = "0.3.0", = ["parallel"] }
Features (v0.3.0)
Core Transforms
| Function | SciPy Equivalent | Description |
|---|---|---|
fft / ifft |
scipy.fft.fft |
Complex-to-complex 1D FFT |
rfft / irfft |
scipy.fft.rfft |
Real-input optimized FFT |
fft2 / ifft2 |
scipy.fft.fft2 |
2D FFT |
fftn / ifftn |
scipy.fft.fftn |
N-dimensional FFT |
rfft2 / irfft2 |
scipy.fft.rfft2 |
2D real FFT |
rfftn / irfftn |
scipy.fft.rfftn |
N-dimensional real FFT |
fftfreq / rfftfreq |
scipy.fft.fftfreq |
Sample frequency computation |
fftshift / ifftshift |
scipy.fft.fftshift |
Zero-frequency centering |
next_fast_len |
scipy.fft.next_fast_len |
Optimal FFT size selection |
DCT and DST Variants
- DCT types I, II, III, IV, V, VI, VII, VIII
- DST types I, II, III, IV, V, VI, VII, VIII
- Inverse transforms for all types
- MDCT (Modified DCT) and MDST
- N-dimensional DCT/DST
Window Functions Library
100+ window functions including:
- Standard: Hann, Hamming, Blackman, Bartlett, flat-top
- Kaiser, Gaussian, Tukey, Parzen, Bohman
- Nuttall, Blackman-Harris, Blackman-Nuttall
- DPSS (discrete prolate spheroidal sequences) for multi-taper
- Exponential, triangular, rectangular (boxcar)
- General cosine and general Hamming families
- Kaiser-Bessel derived (KBD)
Short-Time Fourier Transform
stft/istftwith configurable window, overlap, and boundary handlingspectrogram(power spectral density)- Normalized spectrogram for visualization
- Waterfall plot data generation (3D mesh, line stacks)
- Coherence and cross-spectral density
Sparse FFT (Sub-Linear Time)
- Sublinear sparse FFT (O(k log n) for k-sparse signals)
- Compressed sensing-based sparse FFT
- Iterative sparse FFT (robust to noise)
- Frequency pruning variant
- Prony method for damped sinusoid recovery
- MUSIC algorithm for super-resolution spectral estimation
- Batch sparse FFT (parallel CPU processing)
- GPU-accelerated sparse FFT (CUDA/ROCm/SYCL via feature flag)
Specialized Transforms
- Fractional Fourier Transform (FrFT) — 3 algorithm variants (Ozaktas-Arikan, Candan, sampling)
- Chirp-Z Transform (CZT) — FFT on arbitrary contours in the z-plane
- Non-Uniform FFT (NUFFT) types 1, 2, and 3 (Gaussian / sinc interpolation)
- Fast Hankel Transform (FHT)
- Hilbert transform (analytic signal)
- Hartley transform
- Number-theoretic Transform (NTT) over prime fields
- Bluestein's algorithm for prime-length FFT
- Mixed-radix FFT (arbitrary composite lengths)
Spectral Estimation
- Lomb-Scargle periodogram for irregularly sampled data
- MUSIC (Multiple Signal Classification) algorithm
- ESPRIT algorithm for frequency estimation
- Burg method (AR model-based PSD)
- Welch's method for PSD estimation
- Multitaper spectral analysis (DPSS windows)
Wavelet Packets
- Wavelet packet transform tree
- Best-basis selection (entropy criterion)
- Reconstruction from wavelet packet tree
- Available wavelet families: Daubechies, Symlets, Coiflets, Biorthogonal
Polyphase Filter Bank
- Analysis and synthesis polyphase filter banks
- Critically sampled and oversampled configurations
- Perfect reconstruction condition verification
- DFT modulated filter banks
Hilbert-Huang Transform (HHT)
- Empirical Mode Decomposition (EMD) into Intrinsic Mode Functions (IMFs)
- Instantaneous frequency and amplitude via Hilbert transform
- Ensemble EMD (EEMD) and Complete EEMD (CEEMDAN) for noise-assisted decomposition
- Hilbert spectrum visualization data
Multidimensional FFT Utilities
- Row-column decomposition for 2D FFT
- Separable N-dimensional FFT plans
- Mixed-radix N-dimensional FFT
- In-place 2D FFT with memory-efficient tiling
Convolution and Correlation
- Overlap-save and overlap-add convolution
- Circular convolution via FFT
- Cross-correlation and autocorrelation
- FFT-based polynomial multiplication
Plan Caching and Execution
- Automatic plan reuse for repeated same-size transforms (thread-safe cache)
- Parallel planner: create multiple plans concurrently
- Parallel executor: execute batch FFTs across worker threads
- Memory-efficient streaming FFT for large arrays
Usage Examples
Basic 1D FFT
use ;
let signal = vec!;
// Complex FFT
let spectrum = fft?;
// Inverse FFT
let recovered = ifft?;
// Real FFT (more efficient for real inputs)
let real_spectrum = rfft?; // length = n/2 + 1
DCT
use ;
let data = vec!;
let coeffs = dct?; // DCT-II (most common)
let back = idct?;
STFT and Spectrogram
use ;
let fs = 44100.0_f64;
let signal: = .map.collect;
// Short-Time Fourier Transform
let = stft?;
// Power spectral density spectrogram
let = spectrogram?;
Fractional Fourier Transform
use frft;
let signal: = .map.collect;
// alpha = 0.5: halfway between time and frequency domain
let result = frft?;
Sparse FFT
use ;
// Signal with only a few significant frequency components
let result = sparse_fft?;
println!;
println!;
Lomb-Scargle Periodogram
use lomb_scargle;
// Irregularly sampled time series
let times: = vec!;
let values: = vec!;
let frequencies: = .map.collect;
let power = lomb_scargle?;
NTT (Number-Theoretic Transform)
use ntt;
let data: = vec!;
let prime = 998_244_353_u64; // NTT-friendly prime
let result = ntt?;
Wavelet Packet Transform
use ;
let signal: = .map.collect;
let tree = new?;
let best_basis = tree.best_basis?;
Feature Flags
| Feature | Description |
|---|---|
parallel |
Multi-threaded FFT execution and batch processing via Rayon |
simd |
SIMD-accelerated butterfly operations and window application |
gpu |
GPU-accelerated sparse FFT (CUDA/ROCm/SYCL, requires scirs2-core gpu) |
cuda |
NVIDIA CUDA sparse FFT backend |
hip |
AMD ROCm/HIP sparse FFT backend |
sycl |
Cross-platform SYCL sparse FFT backend |
Links
License
Licensed under the Apache License 2.0. See LICENSE for details.