Struct spectrum_analyzer::FrequencySpectrum [−][src]
Convenient wrapper around the processed FFT result which describes each frequency and
its value/amplitude in the analyzed slice of samples. It only consists of the frequencies
which were desired, e.g. specified via
crate::limit::FrequencyLimit
when crate::samples_fft_to_spectrum
was called.
Implementations
impl FrequencySpectrum
[src]
pub fn new(
data: Vec<(Frequency, FrequencyValue)>,
frequency_resolution: f32
) -> Self
[src]
data: Vec<(Frequency, FrequencyValue)>,
frequency_resolution: f32
) -> Self
Creates a new object. Calculates several metrics on top of the passed vector.
Parameters
data
Vector with all (Frequency
,FrequencyValue
)-tuplesfrequency_resolution
Resolution in Hertz. This equals todata[1].0 - data[0].0
.
pub fn apply_complex_scaling_fn(
&self,
total_scaling_fn: ComplexSpectrumScalingFunction
)
[src]
&self,
total_scaling_fn: ComplexSpectrumScalingFunction
)
Applies the function generated by total_scaling_fn
to each element and updates
min
, max
, etc. afterwards accordingly.
Parameters
total_scaling_fn
See [crate::spectrum::SpectrumTotalScaleFunctionFactory
].
pub fn average(&self) -> FrequencyValue
[src]
Getter for FrequencySpectrum::average
.
pub fn median(&self) -> FrequencyValue
[src]
Getter for FrequencySpectrum::median
.
pub fn max(&self) -> (Frequency, FrequencyValue)
[src]
Getter for FrequencySpectrum::max
.
pub fn min(&self) -> (Frequency, FrequencyValue)
[src]
Getter for FrequencySpectrum::min
.
pub fn range(&self) -> FrequencyValue
[src]
Returns [FrequencySpectrum::max().1
] - [FrequencySpectrum::min().1
],
i.e. the range of the frequency values (not the frequencies itself,
but their amplitude/value).
pub fn data(&self) -> Ref<'_, Vec<(Frequency, FrequencyValue)>>
[src]
Getter for FrequencySpectrum::data
.
pub fn frequency_resolution(&self) -> f32
[src]
Getter for FrequencySpectrum::frequency_resolution
.
pub fn freq_val_exact(&self, search_fr: f32) -> FrequencyValue
[src]
Returns the value of the given frequency from the spectrum either exactly or approximated.
If search_fr
is not exactly given in the spectrum, i.e. due to the
[self::frequency_resolution
], this function takes the two closest
neighbors/points (A, B), put a linear function through them and calculates
the point C in the middle. This is done by using
[calculate_point_between_points
].
Panics
If parameter search_fr
(frequency) is below the lowest or the maximum
frequency, this function panics! This is because the user provide
the min/max frequency when the spectrum is created and knows about it.
This is similar to an intended “out of bounds”-access.
Parameters
search_fr
The frequency of that you want the amplitude/value in the spectrum.
Return
Either exact value of approximated value, determined by [self::frequency_resolution
].
pub fn freq_val_closest(&self, search_fr: f32) -> (Frequency, FrequencyValue)
[src]
Returns the frequency closest to parameter search_fr
in the spectrum. For example
if the spectrum looks like this:
Vector: [0] [1] [2] [3]
Frequency 100 Hz 200 Hz 300 Hz 400 Hz
Fr Value 0.0 1.0 0.5 0.1
then get_frequency_value_closest(320)
will return (300.0, 0.5)
.
Panics
If parameter search_fre
(frequency) is below the lowest or the maximum
frequency, this function panics!
Parameters
search_fr
The frequency of that you want the amplitude/value in the spectrum.
Return
Closest matching point in spectrum, determined by [self::frequency_resolution
].
pub fn to_map(
&self,
scale_fn: Option<&dyn Fn(f32) -> u32>
) -> BTreeMap<u32, f32>
[src]
&self,
scale_fn: Option<&dyn Fn(f32) -> u32>
) -> BTreeMap<u32, f32>
Returns a BTreeMap
. The key is of type u32.
(f32
is not Ord
, hence we can’t use it as key.) You can optionally specify a
scale function, e.g. multiply all frequencies with 1000 for better
accuracy when represented as unsigned integer.
Parameters
scale_fn
optional scale function, e.g. multiply all frequencies with 1000 for better accuracy when represented as unsigned integer.
Return
New BTreeMap
from frequency to frequency value.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for FrequencySpectrum
impl Send for FrequencySpectrum
impl !Sync for FrequencySpectrum
impl Unpin for FrequencySpectrum
impl UnwindSafe for FrequencySpectrum
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,