Skip to main content

energy_band

Function energy_band 

Source
pub fn energy_band(
    mag: &[f32],
    sample_rate: f32,
    f_lo: f32,
    f_hi: f32,
) -> Result<f32, AudioError>
Expand description

Spectral energy of a one-sided magnitude spectrum mag within the frequency band [f_lo, f_hi] (Hz, inclusive).

mag spans DC..Nyquist inclusive, so bin k sits at k · sample_rate / (2·(N-1)) Hz for an N-bin spectrum. Energy is the sum of squared magnitudes Σ |X[k]|^2 over the bins whose centre frequency falls in [f_lo, f_hi].

Zero-heap: single pass, scalar result.

§Errors

  • AudioError::InvalidParameter if sample_rate is not a positive finite, if mag has fewer than 2 bins, if f_lo is negative, or if f_hi < f_lo.