Skip to content

Algorithms | latest | spectral-rolloff

Spectral rolloff

The n% spectral roll-off point is defined as the frequency below which n% of the total energy of the spectrum is contained. It is computed from the power spectrum Xp=|X|2RM.

The n% roll-off point is estimated by iteratively increasing r[0,M) in the following equation until the equation becomes valid:

m=0rXp[m]n100m=0M1Xp[m]

The roll-off frequency frolloff can be computed from r and the sampling rate fs:

frolloff=fs2rM

Typical values for n are 95, 90, 75 and 50 %.

Parameters

NameDescriptionUnitLimits
rolloffRoll-off point n%[0, 100]

References

  • Peeters, G. (2004). A large set of audio features for sound description (similarity and classification) in the CUIDADO project. In CUIDADO IST Project Report (Vol. 54).
  • 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 spectral_rolloff(spectrum: np.ndarray, samplerate: float, rolloff: int):
    ps = np.abs(spectrum) ** 2
    ps_sum_rolloff = (rolloff / 100) * np.sum(ps)
    ps_sum = 0.0
    for i, magnitude in enumerate(ps):
        ps_sum += magnitude
        if ps_sum >= ps_sum_rolloff:
            return 0.5 * samplerate / (len(ps) - 1) * i
    return 0.5 * samplerate
Run in playground