pub struct FftPlanner { /* private fields */ }Expand description
A reusable FFT planner for efficient repeated FFT operations.
This planner caches FFT plans internally, making repeated FFT operations
of the same size much more efficient than calling fft() repeatedly.
§Examples
use spectrograms::*;
use non_empty_slice::non_empty_vec;
let mut planner = FftPlanner::new();
// Process multiple signals of the same size efficiently
for _ in 0..100 {
let signal = non_empty_vec![0.0; nzu!(512)];
let spectrum = planner.fft(&signal, nzu!(512))?;
// ... process spectrum ...
}Implementations§
Source§impl FftPlanner
impl FftPlanner
Sourcepub fn fft(
&mut self,
samples: &NonEmptySlice<f64>,
n_fft: NonZeroUsize,
) -> SpectrogramResult<Array1<Complex<f64>>>
pub fn fft( &mut self, samples: &NonEmptySlice<f64>, n_fft: NonZeroUsize, ) -> SpectrogramResult<Array1<Complex<f64>>>
Compute forward FFT, reusing cached plans.
This is more efficient than calling the standalone fft() function
repeatedly for the same FFT size.
§Automatic Zero-Padding
If the input signal is shorter than n_fft, it will be automatically
zero-padded to the required length.
§Errors
Returns InvalidInput error if the input length exceeds n_fft.
§Examples
use spectrograms::*;
use non_empty_slice::non_empty_vec;
let mut planner = FftPlanner::new();
let signal = non_empty_vec![1.0; nzu!(512)];
let spectrum = planner.fft(&signal, nzu!(512))?;
assert_eq!(spectrum.len(), 257); // 512/2 + 1Sourcepub fn rfft(
&mut self,
samples: &NonEmptySlice<f64>,
n_fft: NonZeroUsize,
) -> SpectrogramResult<Array1<f64>>
pub fn rfft( &mut self, samples: &NonEmptySlice<f64>, n_fft: NonZeroUsize, ) -> SpectrogramResult<Array1<f64>>
Compute forward real FFT magnitude
§Errors
Returns an error if:
n_fftdoesn’t match the samples length
Sourcepub fn irfft(
&mut self,
spectrum: &NonEmptySlice<Complex<f64>>,
n_fft: NonZeroUsize,
) -> SpectrogramResult<NonEmptyVec<f64>>
pub fn irfft( &mut self, spectrum: &NonEmptySlice<Complex<f64>>, n_fft: NonZeroUsize, ) -> SpectrogramResult<NonEmptyVec<f64>>
Compute inverse FFT, reusing cached plans.
This is more efficient than calling the standalone irfft() function
repeatedly for the same FFT size.
§Errors
Returns an error if:
- The calculated expected length of
spectrumdoesn’t match its actual length
§Examples
use spectrograms::*;
use non_empty_slice::{non_empty_vec, NonEmptySlice};
let mut planner = FftPlanner::new();
// Forward FFT
let signal = non_empty_vec![1.0; nzu!(512)];
let spectrum = planner.fft(&signal, nzu!(512))?;
// Inverse FFT
let spectrum_slice = NonEmptySlice::new(spectrum.as_slice().unwrap()).unwrap();
let reconstructed = planner.irfft(spectrum_slice, nzu!(512))?;
assert_eq!(reconstructed.len(), nzu!(512));Sourcepub fn power_spectrum(
&mut self,
samples: &NonEmptySlice<f64>,
n_fft: NonZeroUsize,
window: Option<WindowType>,
) -> SpectrogramResult<NonEmptyVec<f64>>
pub fn power_spectrum( &mut self, samples: &NonEmptySlice<f64>, n_fft: NonZeroUsize, window: Option<WindowType>, ) -> SpectrogramResult<NonEmptyVec<f64>>
Compute power spectrum with optional windowing, reusing cached plans.
§Automatic Zero-Padding
If the input signal is shorter than n_fft, it will be automatically
zero-padded to the required length.
§Errors
Returns InvalidInput error if the input length exceeds n_fft.
§Examples
use spectrograms::*;
use non_empty_slice::non_empty_vec;
let mut planner = FftPlanner::new();
let signal = non_empty_vec![1.0; nzu!(512)];
let power = planner.power_spectrum(&signal, nzu!(512), Some(WindowType::Hanning))?;
assert_eq!(power.len(), nzu!(257));Sourcepub fn magnitude_spectrum(
&mut self,
samples: &NonEmptySlice<f64>,
n_fft: NonZeroUsize,
window: Option<WindowType>,
) -> SpectrogramResult<NonEmptyVec<f64>>
pub fn magnitude_spectrum( &mut self, samples: &NonEmptySlice<f64>, n_fft: NonZeroUsize, window: Option<WindowType>, ) -> SpectrogramResult<NonEmptyVec<f64>>
Compute magnitude spectrum with optional windowing, reusing cached plans.
§Automatic Zero-Padding
If the input signal is shorter than n_fft, it will be automatically
zero-padded to the required length.
§Errors
Returns InvalidInput error if the input length exceeds n_fft.
§Examples
use spectrograms::*;
use non_empty_slice::non_empty_vec;
let mut planner = FftPlanner::new();
let signal = non_empty_vec![1.0; nzu!(512)];
let magnitude = planner.magnitude_spectrum(&signal, nzu!(512), Some(WindowType::Hanning))?;
assert_eq!(magnitude.len(), nzu!(257));