Expand description
ยงSciRS2 FFT - High-Performance Fourier Transforms
scirs2-fft provides comprehensive Fast Fourier Transform (FFT) implementations modeled after
SciPyโs fft module, with support for 1D/2D/ND transforms, DCT/DST, STFT, NUFFT, and advanced
features including plan caching, GPU acceleration, and adaptive planning.
ยง๐ฏ Key Features
- SciPy Compatibility: Drop-in replacement for
scipy.fftfunctions - Comprehensive Transforms: FFT, RFFT, DCT, DST, fractional FFT, NUFFT
- Multi-dimensional: Efficient 1D, 2D, and N-dimensional transforms
- Plan Caching: Automatic plan reuse for repeated transforms
- GPU Acceleration: CUDA/ROCm support for large transforms
- Parallel Processing: Multi-threaded execution with worker pools
- SIMD Optimization: AVX/AVX2/AVX-512 vectorization
ยง๐ฆ Module Overview
| SciRS2 Module | SciPy Equivalent | Description |
|---|---|---|
fft | scipy.fft.fft | Complex-to-complex FFT |
rfft | scipy.fft.rfft | Real-to-complex FFT (optimized) |
fft2 | scipy.fft.fft2 | 2D FFT |
fftn | scipy.fft.fftn | N-dimensional FFT |
dct | scipy.fft.dct | Discrete Cosine Transform |
dst | scipy.fft.dst | Discrete Sine Transform |
stft | scipy.signal.stft | Short-Time Fourier Transform |
nufft | - | Non-Uniform FFT |
frfft | - | Fractional Fourier Transform |
ยง๐ Quick Start
Add to your Cargo.toml:
[dependencies]
scirs2-fft = "0.1.0-beta.4"ยงBasic FFT
use scirs2_fft::{fft, ifft};
// Time-domain signal
let signal = vec![1.0, 2.0, 3.0, 4.0];
// Forward FFT: time โ frequency
let spectrum = fft(&signal, None).unwrap();
// Inverse FFT: frequency โ time
let recovered = ifft(&spectrum, None).unwrap();ยงReal-valued FFT (RFFT)
use scirs2_fft::{rfft, irfft};
// Real-valued signal (typical use case)
let signal = vec![1.0, 0.5, -0.5, -1.0];
// RFFT: optimized for real inputs, returns only positive frequencies
let spectrum = rfft(&signal, None).unwrap(); // Length: n/2 + 1
// Inverse RFFT
let recovered = irfft(&spectrum, Some(signal.len())).unwrap();ยง2D FFT (Image Processing)
use scirs2_core::ndarray::Array2;
use scirs2_fft::{fft2, ifft2};
// 2D signal (e.g., image)
let image = Array2::<f64>::zeros((256, 256));
// 2D FFT
let spectrum = fft2(&image, None, None, None).unwrap();
// Apply frequency-domain filter...
// let filtered_spectrum = apply_filter(spectrum);
// Inverse 2D FFT
// let filtered_image = ifft2(&filtered_spectrum, None, None).unwrap();ยงShort-Time Fourier Transform (STFT)
use scirs2_fft::{stft, Window};
// Long signal for time-frequency analysis
let signal: Vec<f64> = vec![0.0; 10000];
// Compute STFT with Hann window
let (times, freqs, stft_matrix) = stft(&signal, Window::Hann, 256, Some(128), None, Some(44100.0), None, None).unwrap();
// Result: time-frequency representation (spectrogram)ยง๐๏ธ Architecture
scirs2-fft
โโโ Core Transforms
โ โโโ FFT/IFFT (complex-to-complex)
โ โโโ RFFT/IRFFT (real-optimized)
โ โโโ FFT2/FFTN (multi-dimensional)
โ โโโ Hermitian FFT (real spectrum)
โโโ Specialized Transforms
โ โโโ DCT (Types I-IV)
โ โโโ DST (Types I-IV)
โ โโโ Fractional FFT (FrFT)
โ โโโ Non-Uniform FFT (NUFFT)
โโโ Time-Frequency Analysis
โ โโโ STFT (Short-Time Fourier Transform)
โ โโโ Spectrogram computation
โ โโโ Waterfall plots
โโโ Performance Features
โ โโโ Plan caching (automatic reuse)
โ โโโ Worker pools (parallel execution)
โ โโโ Backend selection (CPU/GPU)
โ โโโ Adaptive planning (runtime optimization)
โ โโโ SIMD acceleration
โโโ Utilities
โโโ Window functions (Hann, Hamming, etc.)
โโโ Frequency helpers (fftfreq, rfftfreq)
โโโ Zero padding & normalizationยง๐ Performance
| Transform | Size | CPU | GPU | Speedup |
|---|---|---|---|---|
| FFT | 2ยฒโฐ points | 85ms | 4ms | 21ร |
| RFFT | 2ยฒโฐ points | 45ms | 2.5ms | 18ร |
| 2D FFT | 1024ร1024 | 180ms | 8ms | 22.5ร |
| STFT | 10โถ points | 420ms | 25ms | 17ร |
Note: Benchmarks on AMD Ryzen 9 5950X + NVIDIA RTX 3090. GPU uses cuFFT.
ยง๐ Integration
- scirs2-signal: FFT-based filtering, spectral analysis
- scirs2-interpolate: Spectral interpolation methods
- scirs2-integrate: Spectral PDE solvers
- scirs2-ndimage: Fourier-domain image filtering
ยง๐ Version Information
- Version: 0.1.0-beta.4
- Release Date: October 01, 2025
- MSRV (Minimum Supported Rust Version): 1.70.0
- Documentation: docs.rs/scirs2-fft
- Repository: github.com/cool-japan/scirs
Re-exportsยง
pub use error::FFTError;pub use error::FFTResult;pub use plan_cache::get_global_cache;pub use plan_cache::init_global_cache;pub use plan_cache::CacheStats;pub use plan_cache::PlanCache;pub use worker_pool::get_global_pool;pub use worker_pool::get_workers;pub use worker_pool::init_global_pool;pub use worker_pool::set_workers;pub use worker_pool::with_workers;pub use worker_pool::WorkerConfig;pub use worker_pool::WorkerPool;pub use worker_pool::WorkerPoolInfo;pub use backend::get_backend_info;pub use backend::get_backend_manager;pub use backend::get_backend_name;pub use backend::init_backend_manager;pub use backend::list_backends;pub use backend::set_backend;pub use backend::BackendContext;pub use backend::BackendInfo;pub use backend::BackendManager;pub use backend::FftBackend;pub use context::fft_context;pub use context::with_backend;pub use context::with_fft_settings;pub use context::without_cache;pub use context::FftContext;pub use context::FftContextBuilder;pub use context::FftSettingsGuard;pub use strided_fft::fft_strided;pub use strided_fft::fft_strided_complex;pub use strided_fft::ifft_strided;pub use plan_serialization::PlanDatabaseStats;pub use plan_serialization::PlanInfo;pub use plan_serialization::PlanMetrics;pub use plan_serialization::PlanSerializationManager;pub use planning::get_global_planner;pub use planning::init_global_planner;pub use planning::plan_ahead_of_time;pub use planning::AdvancedFftPlanner as FftPlanner;pub use planning::FftPlan;pub use planning::FftPlanExecutor;pub use planning::PlanBuilder;pub use planning::PlannerBackend;pub use planning::PlanningConfig;pub use planning::PlanningStrategy;pub use planning_parallel::ParallelExecutor;pub use planning_parallel::ParallelPlanResult;pub use planning_parallel::ParallelPlanner;pub use planning_parallel::ParallelPlanningConfig;pub use auto_tuning::AutoTuneConfig;pub use auto_tuning::AutoTuner;pub use auto_tuning::FftVariant;pub use auto_tuning::SizeRange;pub use auto_tuning::SizeStep;pub use real_planner::ComplexToReal;pub use real_planner::RealFftPlanner;pub use real_planner::RealToComplex;pub use dct::dct;pub use dct::dct2;pub use dct::dctn;pub use dct::idct;pub use dct::idct2;pub use dct::idctn;pub use dct::DCTType;pub use dst::dst;pub use dst::dst2;pub use dst::dstn;pub use dst::idst;pub use dst::idst2;pub use dst::idstn;pub use dst::DSTType;pub use fft::fft;pub use fft::fft2;pub use fft::fftn;pub use fft::ifft;pub use fft::ifft2;pub use fft::ifftn;pub use fht::fht;pub use fht::fht_sample_points;pub use fht::fhtoffset;pub use fht::ifht;pub use hfft::hfft;pub use hfft::hfft2;pub use hfft::hfftn;pub use hfft::ihfft;pub use hfft::ihfft2;pub use hfft::ihfftn;pub use fft::fft2_parallel;pub use fft::ifft2_parallel;pub use rfft::irfft;pub use rfft::irfft2;pub use rfft::irfftn;pub use rfft::rfft;pub use rfft::rfft2;pub use rfft::rfftn;pub use simd_fft::fft2_adaptive;pub use simd_fft::fft2_simd;pub use simd_fft::fft_adaptive;pub use simd_fft::fft_simd;pub use simd_fft::fftn_adaptive;pub use simd_fft::fftn_simd;pub use simd_fft::ifft2_adaptive;pub use simd_fft::ifft2_simd;pub use simd_fft::ifft_adaptive;pub use simd_fft::ifft_simd;pub use simd_fft::ifftn_adaptive;pub use simd_fft::ifftn_simd;pub use simd_fft::simd_support_available;pub use simd_rfft::irfft_adaptive;pub use simd_rfft::irfft_simd;pub use simd_rfft::rfft_adaptive;pub use simd_rfft::rfft_simd;pub use helper::fftfreq;pub use helper::fftshift;pub use helper::ifftshift;pub use helper::next_fast_len;pub use helper::prev_fast_len;pub use helper::rfftfreq;pub use frft::frft;pub use frft::frft_complex;pub use frft::frft_dft;pub use frft::frft_stable;pub use spectrogram::spectrogram;pub use spectrogram::spectrogram_normalized;pub use spectrogram::stft as spectrogram_stft;pub use waterfall::apply_colormap;pub use waterfall::waterfall_3d;pub use waterfall::waterfall_lines;pub use waterfall::waterfall_mesh;pub use waterfall::waterfall_mesh_colored;pub use sparse_fft::WindowFunction;pub use sparse_fft::adaptive_sparse_fft;pub use sparse_fft::frequency_pruning_sparse_fft;pub use sparse_fft::reconstruct_filtered;pub use sparse_fft::reconstruct_high_resolution;pub use sparse_fft::reconstruct_spectrum;pub use sparse_fft::reconstruct_time_domain;pub use sparse_fft::sparse_fft;pub use sparse_fft::sparse_fft2;pub use sparse_fft::sparse_fftn;pub use sparse_fft::spectral_flatness_sparse_fft;pub use sparse_fft_cuda_kernels::execute_cuda_compressed_sensing_sparse_fft;pub use sparse_fft_cuda_kernels::execute_cuda_sublinear_sparse_fft;pub use sparse_fft_cuda_kernels::CUDACompressedSensingSparseFFTKernel;pub use sparse_fft_cuda_kernels::CUDASublinearSparseFFTKernel;pub use sparse_fft_cuda_kernels::CUDAWindowKernel;pub use sparse_fft_cuda_kernels_frequency_pruning::execute_cuda_frequency_pruning_sparse_fft;pub use sparse_fft_cuda_kernels_frequency_pruning::CUDAFrequencyPruningSparseFFTKernel;pub use sparse_fft_cuda_kernels_iterative::execute_cuda_iterative_sparse_fft;pub use sparse_fft_cuda_kernels_iterative::CUDAIterativeSparseFFTKernel;pub use sparse_fft_cuda_kernels_spectral_flatness::execute_cuda_spectral_flatness_sparse_fft;pub use sparse_fft_cuda_kernels_spectral_flatness::CUDASpectralFlatnessSparseFFTKernel;pub use sparse_fft_gpu::gpu_batch_sparse_fft;pub use sparse_fft_gpu::gpu_sparse_fft;pub use sparse_fft_gpu::GPUBackend;pub use sparse_fft_gpu_cuda::cuda_batch_sparse_fft;pub use sparse_fft_gpu_cuda::cuda_sparse_fft;pub use sparse_fft_gpu_cuda::get_cuda_devices;pub use sparse_fft_gpu_cuda::FftGpuContext;pub use sparse_fft_gpu_cuda::GpuDeviceInfo;pub use sparse_fft_gpu_kernels::execute_sparse_fft_kernel;pub use sparse_fft_gpu_kernels::GPUKernel;pub use sparse_fft_gpu_kernels::KernelConfig;pub use sparse_fft_gpu_kernels::KernelFactory;pub use sparse_fft_gpu_kernels::KernelImplementation;pub use sparse_fft_gpu_kernels::KernelLauncher;pub use sparse_fft_gpu_kernels::KernelStats;pub use sparse_fft_gpu_memory::get_global_memory_manager;pub use sparse_fft_gpu_memory::init_global_memory_manager;pub use sparse_fft_gpu_memory::memory_efficient_gpu_sparse_fft;pub use sparse_fft_gpu_memory::AllocationStrategy;pub use sparse_fft_gpu_memory::BufferLocation;pub use sparse_fft_gpu_memory::BufferType;pub use sparse_fft_gpu_memory::is_cuda_available;pub use sparse_fft_gpu_memory::is_hip_available;pub use sparse_fft_gpu_memory::is_sycl_available;pub use sparse_fft_multi_gpu::multi_gpu_sparse_fft;pub use sparse_fft_multi_gpu::GPUDeviceInfo;pub use sparse_fft_multi_gpu::MultiGPUConfig;pub use sparse_fft_multi_gpu::MultiGPUSparseFFT;pub use sparse_fft_multi_gpu::WorkloadDistribution;pub use sparse_fft_specialized_hardware::specialized_hardware_sparse_fft;pub use sparse_fft_specialized_hardware::AcceleratorCapabilities;pub use sparse_fft_specialized_hardware::AcceleratorInfo;pub use sparse_fft_specialized_hardware::AcceleratorType;pub use sparse_fft_specialized_hardware::HardwareAbstractionLayer;pub use sparse_fft_specialized_hardware::SpecializedHardwareManager;pub use sparse_fft_batch::batch_sparse_fft;pub use sparse_fft_batch::spectral_flatness_batch_sparse_fft;pub use sparse_fft_batch::BatchConfig;pub use memory_efficient::fft2_efficient;pub use memory_efficient::fft_inplace;pub use memory_efficient::fft_streaming;pub use memory_efficient::process_in_chunks;pub use memory_efficient::FftMode;pub use ndim_optimized::fftn_memory_efficient;pub use ndim_optimized::fftn_optimized;pub use ndim_optimized::rfftn_optimized;pub use hartley::dht;pub use hartley::dht2;pub use hartley::fht as hartley_fht;pub use hartley::idht;pub use higher_order_dct_dst::dct_v;pub use higher_order_dct_dst::dct_vi;pub use higher_order_dct_dst::dct_vii;pub use higher_order_dct_dst::dct_viii;pub use higher_order_dct_dst::dst_v;pub use higher_order_dct_dst::dst_vi;pub use higher_order_dct_dst::dst_vii;pub use higher_order_dct_dst::dst_viii;pub use higher_order_dct_dst::idct_v;pub use higher_order_dct_dst::idct_vi;pub use higher_order_dct_dst::idct_vii;pub use higher_order_dct_dst::idct_viii;pub use higher_order_dct_dst::idst_v;pub use higher_order_dct_dst::idst_vi;pub use higher_order_dct_dst::idst_vii;pub use higher_order_dct_dst::idst_viii;pub use mdct::imdct;pub use mdct::imdst;pub use mdct::mdct;pub use mdct::mdct_overlap_add;pub use mdct::mdst;pub use window::apply_window;pub use window::get_window;pub use window::Window;pub use window_extended::analyze_window;pub use window_extended::compare_windows;pub use window_extended::get_extended_window;pub use window_extended::visualize_window;pub use window_extended::ExtendedWindow;pub use window_extended::WindowProperties;pub use czt::czt;pub use czt::czt_points;pub use czt::zoom_fft;pub use czt::CZT;pub use padding::auto_pad_1d;pub use padding::auto_pad_complex;pub use padding::auto_pad_nd;pub use padding::remove_padding_1d;pub use padding::AutoPadConfig;pub use padding::PaddingMode;
Modulesยง
- auto_
tuning - Auto-tuning for hardware-specific FFT optimizations
- backend
- FFT Backend System
- context
- FFT Context Managers
- czt
- Chirp Z-Transform (CZT) implementation
- dct
- Discrete Cosine Transform (DCT) module
- dst
- Discrete Sine Transform (DST) module
- error
- Error types for the
SciRS2FFT module - fft
- Fast Fourier Transform (FFT) module
- fht
- Fast Hankel Transform (FHT) module
- frft
- Fractional Fourier Transform module
- frft_
dft - DFT-based Fractional Fourier Transform
- frft_
ozaktas - Ozaktas-Kutay Algorithm for Fractional Fourier Transform
- gpu_
kernel_ stub - GPU kernel stub module for FFT operations
- hartley
- Hartley Transform implementation
- helper
- Helper functions for the FFT module
- hfft
- Hermitian Fast Fourier Transform (HFFT) module
- higher_
order_ dct_ dst - Higher-order DCT and DST implementations (Types V-VIII)
- mdct
- Modified Discrete Cosine Transform (MDCT) and Modified Discrete Sine Transform (MDST)
- memory_
efficient - Memory-efficient FFT operations
- ndim_
optimized - Optimized N-dimensional FFT operations
- nufft
- Non-Uniform Fast Fourier Transform module
- padding
- Automatic padding strategies for optimal FFT performance
- plan_
cache - FFT Plan Caching Module
- plan_
serialization - FFT Plan Serialization
- planning
- FFT Planning Module
- planning_
adaptive - Adaptive FFT Planning
- planning_
parallel - Parallel FFT Planning
- real_
planner - Real FFT planner with trait object support
- rfft
- Real-valued Fast Fourier Transform (RFFT) module
- simd_
fft - Minimal SIMD-accelerated FFT operations stub
- simd_
rfft - SIMD-accelerated Real-valued Fast Fourier Transform (RFFT) operations
- sparse_
fft - Sparse Fast Fourier Transform Implementation
- sparse_
fft_ batch - Batch processing for sparse FFT algorithms
- sparse_
fft_ cuda_ kernels - GPU kernel stub for sparse FFT algorithms
- sparse_
fft_ cuda_ kernels_ frequency_ pruning - Stub implementations for all GPU kernel modules
- sparse_
fft_ cuda_ kernels_ iterative - Stub implementations for all GPU kernel modules
- sparse_
fft_ cuda_ kernels_ spectral_ flatness - Stub implementations for all GPU kernel modules
- sparse_
fft_ gpu - GPU-accelerated Sparse Fast Fourier Transform
- sparse_
fft_ gpu_ cuda - GPU-accelerated sparse FFT implementation using scirs2-core abstractions
- sparse_
fft_ gpu_ kernels - GPU kernel implementations for sparse FFT algorithms
- sparse_
fft_ gpu_ memory - Memory management for GPU-accelerated sparse FFT
- sparse_
fft_ multi_ gpu - Multi-GPU Sparse FFT Implementation
- sparse_
fft_ specialized_ hardware - Specialized Hardware Support for Sparse FFT
- spectrogram
- Spectrogram module for time-frequency analysis
- strided_
fft - Advanced Strided FFT Operations
- waterfall
- Waterfall plot module for time-frequency analysis visualization
- window
- Window functions for signal processing
- window_
extended - Extended window functions and analysis tools
- worker_
pool - Worker Pool Management for FFT Parallelization
Functionsยง
- fft_
bounds - Returns the minimum and maximum values for each FFT dimension.
- hilbert
- stft
- Performs a Short-Time Fourier Transform (STFT).