Algorithms | latest | band-energy-ratio
Band energy ratio
The band energy ratio is defined as the ratio of the band energy in an arbitrary frequency band
Where
References
- Eyben, F. (2016). Real-time Speech and Music Classification by Large Audio Feature Space Extraction. https://doi.org/10.1007/978-3-319-27299-3
Code
INFO
The following snippet is written in a generic and unoptimized manner. The code aims to be comprehensible to programmers familiar with various programming languages and may not represent the most efficient or idiomatic Python practices. Please refer to implementations for optimized implementations in different programming languages.
py
import numpy as np
def band_energy_ratio(
spectrum: np.ndarray, samplerate: float, f_lower: float, f_upper: float
) -> float:
powerspectrum = np.abs(spectrum) ** 2
n = len(powerspectrum)
n_lower = int(2 * n * f_lower / samplerate)
n_upper = int(2 * n * f_upper / samplerate)
return np.sum(powerspectrum[n_lower:n_upper]) / np.sum(powerspectrum)