Skip to content

MFCC

Mel-frequency cepstral coefficients: the orthonormal DCT-II of the dB mel spectrogram, the compact per-frame descriptor of classic speech front ends (slaney filterbank, top_db clamp, optional sinusoidal lifter). The mel stage runs the fused kernel; the DCT is a small matrix product over the mel axis.

specux.mfcc(x, *, sr, n_mfcc=20, n_fft=2048, hop_length=None, win_length=None,
window="hann", center=True, n_mels=128, fmin=0.0, fmax=None,
mel_scale="slaney", norm="slaney", lifter=0.0, top_db=80.0,
eps=1e-10, backend="auto")
import numpy as np
import specux
x = np.random.randn(2, 32768).astype(np.float32)
C = specux.mfcc(x, sr=22050, n_mfcc=20)
C.shape # (2, 20, 65) = (..., n_mfcc, n_frames)

Parameters beyond the mel spectrogram

  • n_mfcc: coefficients kept (first rows of the DCT), at most n_mels.
  • lifter: sinusoidal liftering parameter, weighting coefficient k by 1 + (lifter/2) sin(pi k / lifter); 0 disables.
  • top_db: clamp the dB spectrogram at max - top_db per item before the DCT; None disables. Defaults to 80.

The remaining parameters pass through to melspectrogram. For float16 inputs the DCT and lifter stages compute in float32 (they accumulate over the full mel axis) and the result is cast back to float16.

The configured form

t = specux.MFCC(sr=22050, n_mfcc=13)
C = t(x) # (..., n_mfcc, n_frames)
assert specux.MFCC(**t.to_dict()) == t

References

Mel scale [stevens1937], slaney filterbank [slaney1998]; see References.