harmos_storage/signal/spectrum/
mod.rs1#[cfg(feature = "fft")]
13mod bounded;
14mod decibel;
15#[cfg(feature = "fft")]
16mod fourier;
17mod harmonic;
18mod indicator;
19mod taper;
20
21#[cfg(feature = "fft")]
24pub use bounded::fft_in_place;
25pub use decibel::{Decibel, Scale};
26#[cfg(feature = "fft")]
27pub use fourier::{Estimate, Welch, reconstruct, transform};
28pub use harmonic::{fundamental, harmonics, peaks, thd};
29pub use indicator::{band_energy, band_rms, centroid, occupied_bandwidth, papr, rolloff};
30pub use taper::{Band, Taper};
31
32#[derive(Clone, Debug, PartialEq)]
49pub struct Spectrum {
50 pub step: f64,
51 pub real: Vec<f64>,
52 pub imag: Vec<f64>,
53}
54
55impl Spectrum {
62 #[must_use]
63 pub fn rate(&self) -> f64 {
64 match self.real.len() {
65 0 | 1 => 0.0,
66 bins => self.step * ((bins - 1) * 2) as f64,
67 }
68 }
69}
70
71#[must_use]
74pub fn magnitude(real: &[f64], imag: &[f64]) -> Vec<f64> {
75 real.iter().zip(imag).map(|(real, imag)| real.hypot(*imag)).collect()
76}
77
78#[must_use]
79pub fn phase(real: &[f64], imag: &[f64]) -> Vec<f64> {
80 real.iter().zip(imag).map(|(real, imag)| imag.atan2(*real)).collect()
81}
82
83#[must_use]
84pub fn bins(step: f64, count: usize) -> Vec<f64> {
85 (0..count).map(|index| index as f64 * step).collect()
86}
87
88