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::InvalidParameterifsample_rateis not a positive finite, ifmaghas fewer than 2 bins, iff_lois negative, or iff_hi < f_lo.