Crate scirs2_fft

Crate scirs2_fft 

Source
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.fft functions
  • 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 ModuleSciPy EquivalentDescription
fftscipy.fft.fftComplex-to-complex FFT
rfftscipy.fft.rfftReal-to-complex FFT (optimized)
fft2scipy.fft.fft22D FFT
fftnscipy.fft.fftnN-dimensional FFT
dctscipy.fft.dctDiscrete Cosine Transform
dstscipy.fft.dstDiscrete Sine Transform
stftscipy.signal.stftShort-Time Fourier Transform
nufft-Non-Uniform FFT
frfft-Fractional Fourier Transform

ยง๐Ÿš€ Quick Start

Add to your Cargo.toml:

[dependencies]
scirs2-fft = "0.1.0-rc.1"

ยง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

TransformSizeCPUGPUSpeedup
FFT2ยฒโฐ points85ms4ms21ร—
RFFT2ยฒโฐ points45ms2.5ms18ร—
2D FFT1024ร—1024180ms8ms22.5ร—
STFT10โถ points420ms25ms17ร—

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

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 SciRS2 FFT 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).