[−][src]Crate rustfft
RustFFT allows users to compute arbitrary-sized FFTs in O(nlogn) time.
The recommended way to use RustFFT is to create a FFTplanner
instance and then call its
plan_fft
method. This method will automatically choose which FFT algorithms are best
for a given size and initialize the required buffers and precomputed data.
// Perform a forward FFT of size 1234 use std::sync::Arc; use rustfft::FFTplanner; use rustfft::num_complex::Complex; use rustfft::num_traits::Zero; let mut input: Vec<Complex<f32>> = vec![Complex::zero(); 1234]; let mut output: Vec<Complex<f32>> = vec![Complex::zero(); 1234]; let mut planner = FFTplanner::new(false); let fft = planner.plan_fft(1234); fft.process(&mut input, &mut output); // The fft instance returned by the planner is stored behind an `Arc`, so it's cheap to clone let fft_clone = Arc::clone(&fft);
The planner returns trait objects of the FFT
trait, allowing for FFT sizes that aren't known
until runtime.
RustFFT also exposes individual FFT algorithms. If you know beforehand that you need a power-of-two FFT, you can avoid the overhead of the planner and trait object by directly creating instances of the Radix4 algorithm:
// Computes a forward FFT of size 4096 use rustfft::algorithm::Radix4; use rustfft::FFT; use rustfft::num_complex::Complex; use rustfft::num_traits::Zero; let mut input: Vec<Complex<f32>> = vec![Complex::zero(); 4096]; let mut output: Vec<Complex<f32>> = vec![Complex::zero(); 4096]; let fft = Radix4::new(4096, false); fft.process(&mut input, &mut output);
For the vast majority of situations, simply using the FFTplanner
will be enough, but
advanced users may have better insight than the planner into which algorithms are best for a specific size. See the
algorithm
module for a complete list of algorithms implemented by RustFFT.
Normalization
RustFFT does not normalize outputs. Callers must manually normalize the results by scaling each element by
1/len().sqrt()
. Multiple normalization steps can be merged into one via pairwise multiplication, so when
doing a forward FFT followed by an inverse FFT, callers can normalize once by scaling each element by 1/len()
Output Order
Elements in the output are ordered by ascending frequency, with the first element corresponding to frequency 0.
Re-exports
pub extern crate num_complex; |
pub extern crate num_traits; |
Modules
algorithm | Individual FFT algorithms |
Structs
FFTplanner | The FFT planner is used to make new FFT algorithm instances. |
Traits
FFT | An umbrella trait for all available FFT algorithms |
FFTnum | Generic floating point number, implemented for f32 and f64 |
IsInverse | A trait that allows FFT algorithms to report whether they compute forward FFTs or inverse FFTs |
Length | A trait that allows FFT algorithms to report their expected input/output size |