Skip to main content

frequency_bands

Function frequency_bands 

Source
pub fn frequency_bands(
    mag: &[f32],
    sample_rate: f32,
    band_edges_hz: &[f32],
    out_energy: &mut [f32],
) -> Result<usize, AudioError>
Expand description

Sum the energy of a one-sided magnitude spectrum mag into arbitrary frequency bands defined by ascending band_edges_hz.

band_edges_hz holds B + 1 ascending edge frequencies (Hz) partitioning the spectrum into B bands. Band b covers [edge[b], edge[b+1]) (half-open, so a bin lands in exactly one band). out_energy[b] receives Σ |X[k]|^2 over the bins whose centre frequency falls in band b.

mag spans DC..Nyquist inclusive, so bin k sits at k · sample_rate / (2·(N-1)) Hz for an N-bin spectrum.

Zero-heap: single pass, caller-supplied output.

§Errors