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