Module spectrum_analyzer::scaling
source · Expand description
This module contains convenient public transform functions that you can use
as parameters in crate::samples_fft_to_spectrum
for 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.
Structs
- Helper struct for
SpectrumScalingFunction
that is passed into the scaling function together with the current frequency value. This structure can be used to scale each value. All properties reference the current data of acrate::spectrum::FrequencySpectrum
.
Functions
- Combines several scaling functions into a new single one.
- Divides each value by N. Several resources recommend that the FFT result should be divided by the length of samples, so that values of different samples lengths are comparable.
- Like
divide_by_N
but divides each value bysqrt(N)
. This is the recommended scaling in therustfft
documentation (but is generally applicable). See https://docs.rs/rustfft/latest/rustfft/#normalization - Calculates the base 10 logarithm of each frequency magnitude and multiplies it with 20. This scaling is quite common, you can find more information for example here: https://www.sjsu.edu/people/burford.furman/docs/me120/FFT_tutorial_NI.pdf
- Scales each frequency value/amplitude in the spectrum to interval
[0.0; 1.0]
. Function is of typeSpectrumScalingFunction
. Expects thatSpectrumDataStats::min
is not negative.
Type Aliases
- Describes the type for a function that scales/normalizes the data inside
crate::FrequencySpectrum
. The scaling only affects the value/amplitude of the frequency, but not the frequency itself. It is applied to every single element.