Crate spectrum_analyzer
source ·Expand description
An easy to use and fast no_std library (with alloc) to get the frequency
spectrum of a digital signal (e.g. audio) using FFT.
Examples
Scaling via dynamic closure
use spectrum_analyzer::{samples_fft_to_spectrum, FrequencyLimit};
// get data from audio source
let samples = vec![0.0, 1.1, 5.5, -5.5];
let res = samples_fft_to_spectrum(
&samples,
44100,
FrequencyLimit::All,
Some(&|val, info| val - info.min),
);Scaling via static function
use spectrum_analyzer::{samples_fft_to_spectrum, FrequencyLimit};
use spectrum_analyzer::scaling::divide_by_N_sqrt;
// get data from audio source
let samples = vec![0.0, 1.1, 5.5, -5.5];
let res = samples_fft_to_spectrum(
&samples,
44100,
FrequencyLimit::All,
// Recommended scaling/normalization by `rustfft`.
Some(÷_by_N_sqrt),
);Modules
- Errors related to the spectrum analysis via FFT. Most probably, the errors will result in wrong input data, before the actual calculation has begun.
- This module contains convenient public transform functions that you can use as parameters in
crate::samples_fft_to_spectrumfor scaling the frequency value (the FFT result). They act as “idea/inspiration”. Feel free to either compose them or create your own derivation from them. - Several window functions which you can apply before doing the FFT. For more information:
Structs
- Convenient wrapper around the processed FFT result which describes each frequency and its value/amplitude from the analyzed samples. It only contains the frequencies that were desired, e.g., specified via
crate::limit::FrequencyLimitwhencrate::samples_fft_to_spectrumwas called.
Enums
- Can be used to specify a desired frequency limit. If you know that you only need frequencies
f <= 1000Hz,1000 <= f <= 6777, or10000 <= f, then this can help you to accelerate overall computation speed and memory usage. - Possible errors when creating a
FrequencyLimit-object.
Functions
- Takes an array of samples (length must be a power of 2), e.g. 2048, applies an FFT (using the specified FFT implementation) on it and returns all frequencies with their volume/magnitude.
Type Definitions
- A frequency in Hertz. A convenient wrapper type around
f32. - The value of a
Frequencyin a frequency spectrum. Also called the magnitude.