Skip to content

Algorithms | latest | band-energy

Band energy

The band energy is defined as the energy in an arbitrary frequency band [fl,fu), where fl and fu are the lower and upper frequency bounds of the band.

BandEnergy=m=mlmu1Xp[m]Xp=|X|2ml=Mfl2fsmu=Mfu2fs

Where m[0,M) is the bin index of the spectrum X and the power spectrum Xp.

References

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(
    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])
Run in playground