avila-fft
Pure Rust FFT library with zero dependencies - Fast Fourier Transform, Short-Time Fourier Transform (STFT), 2D FFT for images, spectral analysis, and digital filters.
Features
- ✅ Zero external dependencies - Pure Rust implementation
- ✅ Generic float support - Works with
f32andf64 - ✅ 1D FFT - Recursive and iterative in-place algorithms (10-40x faster)
- ✅ Real FFT (RFFT) - Optimized for real signals (~50% faster)
- ✅ 2D FFT - Row-column algorithm for images
- ✅ STFT/ISTFT - Short-Time Fourier Transform with overlap-add reconstruction
- ✅ Spectrogram - Time-frequency analysis with spectral features
- ✅ Window functions - Hamming, Hann, Blackman, Blackman-Harris, Bartlett
- ✅ Spatial filters - Ideal and Gaussian lowpass/highpass/bandpass
- ✅ Spectral analysis - Centroid, bandwidth, flatness, rolloff
- ✅ Scientific tests - 35+ tests validating correctness
- ✅ Benchmarks - Performance comparison suite
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Basic FFT Example
use *;
STFT Example
use *;
2D FFT Example
use *;
API Overview
Core FFT Functions
fft()/ifft()- Recursive Cooley-Tukey algorithmFftPlanner- Iterative in-place FFT with twiddle factor caching (10-40x faster)rfft()/irfft()- Real FFT optimized for real signals
STFT Module (timefreq)
StftProcessor- STFT/ISTFT processor with configurable overlapSpectrogram- Time-frequency representation with analysis methodsOverlapConfig- Overlap configuration (50%, 75%, custom)WindowType- Window function selection
Spectral Analysis Methods
spectral_centroid()- Center of mass of spectrum (brightness)spectral_bandwidth()- Dispersion around centroidspectral_flatness()- Tonality vs noise (0=tonal, 1=noise)spectral_rolloff(%)- Frequency below which X% of energy lies
2D FFT Module (fft2d)
Image2D- 2D complex image structurefft2d()/ifft2d()- 2D FFT using row-column algorithmFft2DPlanner- Cached 2D FFT plannerIdealFilter- Ideal lowpass/highpass/bandpass/bandreject filtersGaussianFilter- Smooth Gaussian filters (no ringing)convolve2d()- 2D convolution via FFT
Window Functions (window)
hann()- Hann window (good frequency resolution)hamming()- Hamming window (reduced sidelobes)blackman()- Blackman window (excellent sidelobe suppression)blackman_harris()- 4-term Blackman-Harris (best sidelobe suppression)bartlett()- Bartlett (triangular) windowrectangular()- Rectangular (no windowing)
Examples
Run the included examples:
# Spectral analysis with windowing
# Performance benchmark
# Image processing with 2D FFT
# Audio analysis with STFT
Performance
Benchmarks on Intel Core i7 (N=1024):
| Algorithm | Time per operation | Throughput |
|---|---|---|
| Recursive FFT | 423 µs | 2.4 Msamples/s |
| Iterative FFT | 23 µs | 44.5 Msamples/s |
| Speedup | 18.4x | - |
The iterative in-place algorithm with twiddle factor caching is 10-40x faster than the recursive implementation.
Testing
Run all tests:
Run benchmarks:
Scientific Correctness
All algorithms are validated with rigorous scientific tests:
- ✅ Parseval's theorem - Energy conservation (error < 1e-15)
- ✅ Reversibility - Perfect reconstruction (RMS error < 1e-16)
- ✅ Linearity - Linear transform property
- ✅ Separability - 2D FFT via 1D transforms
- ✅ Hermitian symmetry - Real signals produce conjugate-symmetric spectra
- ✅ STFT reversibility - ISTFT reconstruction (SNR > 300 dB)
Zero Dependencies
This library has zero external dependencies (only std). All algorithms are implemented from scratch in pure Rust for:
- ✅ Security and auditability
- ✅ Easy integration
- ✅ Minimal binary size
- ✅ Full control over implementation
- ✅ No dependency conflicts
Use Cases
- 🎵 Audio processing - Spectral analysis, pitch detection, effects
- 📷 Image processing - Frequency domain filtering, compression
- 📊 Signal analysis - Time-frequency analysis, spectrograms
- 🔬 Scientific computing - Fourier analysis, convolution
- 📡 Communications - Signal processing, modulation analysis
- 🎙️ Speech processing - Formant analysis, voice recognition
License
Licensed under either of:
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
at your option.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Author
Nícolas Ávila - nicolas@avila.inc