Crate scirs2_fft

Crate scirs2_fft 

Source
Expand description

Fast Fourier Transform module

This module provides implementations of various Fast Fourier Transform algorithms, following SciPy’s fft module.

§Overview

  • Fast Fourier Transform (FFT) and inverse FFT for 1D, 2D, and N-dimensional arrays
  • Real-to-complex and complex-to-real FFT optimized for real-valued data
  • Hermitian-to-real and real-to-Hermitian FFT for complex signals with real spectra
  • Discrete cosine transform (DCT) types I-IV and their inverses
  • Discrete sine transform (DST) types I-IV and their inverses
  • Fractional Fourier Transform (FrFT) for rotations in the time-frequency plane
  • Non-Uniform Fast Fourier Transform (NUFFT) for non-uniformly sampled data
  • Spectrogram and Short-Time Fourier Transform (STFT) for time-frequency analysis
  • Waterfall plots for 3D visualization of time-frequency data
  • Window functions for signal processing (Hann, Hamming, Blackman, etc.)
  • Helper functions for frequency domain calculations and visualization

§Implementation Notes

  • Built on rustfft for efficient computation
  • Provides proper zero padding and array reshaping
  • Normalization options for compatibility with SciPy
  • Support for ndarrays through ndarray integration

§Examples

use scirs2_fft::{fft, ifft};
use num_complex::Complex64;

// Generate a simple signal
let signal = vec![1.0, 2.0, 3.0, 4.0];

// Compute FFT of the signal
let spectrum = fft(&signal, None).unwrap();

// Inverse FFT should recover the original signal
let recovered = ifft(&spectrum, None).unwrap();

// Check that the recovered signal matches the original
for (x, y) in signal.iter().zip(recovered.iter()) {
    assert!((x - y.re).abs() < 1e-10);
    assert!(y.im.abs() < 1e-10);
}

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