MFCC

Mel-frequency cepstral coefficients: the DCT-II of a log-mel frame, truncated to about 13 values, plus deltas and delta-deltas (39 dims). A compact, decorrelated spectral-envelope feature that dominated ASR before deep models switched to log-mels.

8 min read733 wordscore0 viewsupdated 2026-10-15

Definition

MFCC (mel-frequency cepstral coefficients) are the first few coefficients of the discrete cosine transform of a frame's log mel-filterbank energies. Davis and Mermelstein ("Comparison of parametric representations for monosyllabic word recognition in continuously spoken sentences", IEEE Trans. ASSP, 1980) showed that they beat LPC-based features for word recognition. They became the default speech feature for the next three decades.

The word cepstrum (Bogert, Healy and Tukey, 1963) means "the spectrum of a log spectrum". Speech is roughly a source (glottal pulses at F0) filtered by the vocal tract. In the log spectrum the filter and the source add: a slow envelope (the formants) plus a fast ripple (the harmonics). A cosine transform separates slow from fast. Its low-order coefficients describe the envelope, which carries the phone identity. High orders carry the pitch ripple and noise, so they are dropped.

The input is a 25 ms frame; the output is about 13 numbers, versus 201–257 FFT bins or 40 log-mel energies. Classic recognisers modelled these vectors with Gaussian mixture HMMs using diagonal covariances, which only works if the dimensions are nearly uncorrelated. That is exactly what the DCT provides.

The pipeline

MFCC (Davis & Mermelstein 1980) · 16 kHz · one 39-dim vector per 10 ms framewaveformx[n], 16 kHzspeech, 1 s = 16000pre-emphasisy[n] = x[n]− 0.97·x[n−1]boosts highs +6 dB/octframe + window400 samples (25 ms)hop 160, Hamming|FFT|²n_fft 512 → 257 bins31.25 Hz apartmel filterbank26–40 triangles257 → 40 energieslogL_k = ln(M_k + ε)gain → additive offsetDCT-IIΣ L_k cos(πn(k+½)/K)decorrelates bandskeep 13, lifter13 of 40 coefficients× (1 + 11·sin(πn/22))CMNc_t − mean over theutterance: removes thefixed channel/micΔ and ΔΔΔ: regression slopeover ±2 framesΔΔ: same on Δfeature vector13 + 13 + 13 = 39per 10 ms framestaticΔΔΔwhy “cepstrum”envelope1/F08.3 ms at F0 120 HzLow cepstral coefficients = slow envelope (formants, tilt); truncating to 13 drops pitch ripple.
fig.The MFCC recipe at 16 kHz. Row 1: pre-emphasis (y[n] = x[n] − 0.97·x[n−1]) flattens the spectral tilt, 400-sample Hamming frames are taken every 160 samples, and a 512-point FFT gives 257 power bins. Row 2 (right to left): 26–40 mel triangles, a log, and a DCT-II; 13 coefficients are kept and liftered. Row 3: cepstral mean normalisation, Δ and ΔΔ regression, and the 39-dim vector per 10 ms frame. Side note: in a real cepstrum the envelope sits at low quefrency and the pitch at 1/F0 (8.3 ms for 120 Hz).
cn=2−δn0K∑k=0K−1Lkcos⁡ ⁣(πn (k+12)K),n=0,…,12,Lk=ln⁡(Mk+ε)c_n=\sqrt{\tfrac{2-\delta_{n0}}{K}}\sum_{k=0}^{K-1}L_k\cos\!\Big(\frac{\pi n\,(k+\tfrac12)}{K}\Big),\quad n=0,\dots,12,\qquad L_k=\ln\big(M_k+\varepsilon\big)
LkL_k
log energy of mel filter kk in this frame, KK = 20–40 filters
cnc_n
nn-th cepstral coefficient; c0c_0 is proportional to the mean log energy, so it is often replaced by a separate energy term
⋅\sqrt{\cdot}
orthonormal scaling (norm="ortho"), so ∑cn2=∑Lk2\sum c_n^2=\sum L_k^2 and keeping all KK coefficients rebuilds LL exactly

Why the DCT decorrelates. Neighbouring mel filters overlap by half and see the same formant, and overall loudness moves every band together. So the 40 log energies are strongly correlated. For such smooth, highly correlated vectors the DCT is close to the optimal decorrelating transform (the Karhunen–Loève transform, i.e. PCA), and it needs no training data. In 400 synthetic vowel frames with random formants, F0 and ±20 dB level, the mean absolute correlation between log-mel bands was 0.74 (0.94 between neighbours), but only 0.27 among c1,…,c13c_1,\dots,c_{13}.

Lifter, deltas and normalisation

c~n=(1+L2sin⁡πnL)cn,Δct=∑m=1Mm (ct+m−ct−m)2∑m=1Mm2\tilde c_n=\Big(1+\frac{L}{2}\sin\frac{\pi n}{L}\Big)c_n,\qquad \Delta c_t=\frac{\sum_{m=1}^{M}m\,(c_{t+m}-c_{t-m})}{2\sum_{m=1}^{M}m^2}
LL
lifter length, 22 in HTK and Kaldi. It boosts mid-order coefficients (×12 at n=11n=11) so that all have similar variance; it does not change the information
Δct\Delta c_t
delta: least-squares slope of each coefficient over ±M\pm M frames (M=2M=2 is usual). Applying it again gives ΔΔ\Delta\Delta. Static + Δ + ΔΔ = 13 × 3 = 39 dims

Cepstral mean normalisation (CMN). A fixed microphone or channel multiplies the spectrum by G(f)G(f). After the log that becomes an additive constant, and after the DCT it is still a constant vector added to every frame. Subtracting the per-utterance mean of each coefficient removes it. Dividing by the standard deviation as well (CMVN) also equalises the scales.

Common settings

HTK-style recipe
pre-emphasis 0.97, 25 ms Hamming / 10 ms, 26 filters, 12 cepstra + energy, lifter 22, + Δ + ΔΔ → 39
Kaldi defaults
23 mel bins, 13 cepstra (with c0c_0 replaced by log energy), lifter 22
librosa
librosa.feature.mfcc: DCT-II (norm="ortho") of the dB mel spectrogram, n_mfcc=20, no lifter by default
Dimensions
1 s of 16 kHz audio → 98–101 frames × 39 values, versus 16,000 samples
one frame · /ɑ/ (hod) · F0 120 Hz · pre-emphasis 0.97 · Hamming 400 · 40 HTK mel bands— power spectrum · ● log-mel (40) · — inverse DCT of c0…c12 · ┆ formants3010-10-30dBF1F2F32505001k2k4k8kHz, on a mel axisDCT-II coefficients c1…c39 · c0 = -3.5 (log energy, not drawn)110203039keep 13 of 40: envelope RMSE 2.13 dB · 97.5% of c1…c39 energy keptF0 120 Hz: filter centres are < F0/2 apart below 252 Hz → harmonic ripple, carried by high-order c_nlow c_n describe the slow shape (formants, tilt); 13 static + 13 Δ + 13 ΔΔ = the classic 39-dim vector
vowel
options
fig.Cepstral truncation on one frame of a synthetic vowel: 40 HTK log-mel energies (dots), their orthonormal DCT-II (bars), and the envelope rebuilt from the first K coefficients (warm line). Defaults (/ɑ/, F0 120 Hz, pre-emphasis, K = 13): the rebuilt envelope is within 2.13 dB RMS of the log-mel and keeps 97.5% of the energy in c1…c39. K = 4 gives 6.49 dB (76.4%); K = 40 is exact. Raise F0 to 300 Hz and K = 13 gives 5.64 dB (81.9%): sparse harmonics leave dips between mel bands that need high-order terms. The lifter multiplies c1 by 2.57 and c11 by 12.
kL_kRebuilt from c0, c1Error
043.45710.5429
122.6036−0.6036
211.3964−0.3964
310.54290.4571
Worked example: K = 4 log-mel energies L = (4, 2, 1, 1), orthonormal DCT-II, keep c0 and c1

The coefficients are c=(4,  2.2304,  1,  0.1585)c=(4,\;2.2304,\;1,\;0.1585). c0=12∑Lk=4c_0=\tfrac12\sum L_k=4 is the scaled mean, and c1c_1 is the tilt from low to high bands. Energy is preserved: ∑cn2=16+4.9749+1+0.0251=22=∑Lk2\sum c_n^2=16+4.9749+1+0.0251=22=\sum L_k^2. Keeping two coefficients retains 20.97/22=95.3%20.97/22=95.3\% of it, and the reconstruction is the smooth falling line in the table.

A delta by hand (M = 2)

  1. 1One coefficient over frames t−2,…,t+2t-2,\dots,t+2: (1, 2, 4, 5, 5)(1,\,2,\,4,\,5,\,5).
  2. 2Numerator: 1⋅(5−2)+2⋅(5−1)=3+8=111\cdot(5-2)+2\cdot(5-1)=3+8=11.
  3. 3Denominator: 2 (12+22)=102\,(1^2+2^2)=10, so Δct=1.1\Delta c_t=1.1 per frame.

Shapes for 1 s of 16 kHz speech

  1. 116,00016{,}000 samples; 400-sample frames every 160 → ⌊(16,000−400)/160⌋+1=98\lfloor(16{,}000-400)/160\rfloor+1=98 frames.
  2. 2Each frame: 512-point FFT → 257 power bins → 40 mel energies → 40 log values.
  3. 3DCT, keep 13 → 98×1398\times13; add Δ and ΔΔ → 98×39=3,82298\times39=3{,}822 numbers, versus 98×40=3,92098\times40=3{,}920 log-mels or 16,000 samples.
python
1import numpy as np
2
3def mfcc(x, sr=16000, n_fft=512, win=400, hop=160, n_mels=40, n_ceps=13, lifter=22):
4 x = np.append(x[0], x[1:] - 0.97 * x[:-1]) # pre-emphasis
5 frames = np.lib.stride_tricks.sliding_window_view(x, win)[::hop] * np.hamming(win)
6 power = np.abs(np.fft.rfft(frames, n_fft)) ** 2 # (T, 257)
7 mel = lambda f: 2595 * np.log10(1 + f / 700)
8 pts = 700 * (10 ** (np.linspace(0, mel(sr / 2), n_mels + 2) / 2595) - 1)
9 f = np.arange(n_fft // 2 + 1) * sr / n_fft
10 H = np.maximum(0, np.minimum((f - pts[:-2, None]) / (pts[1:-1, None] - pts[:-2, None]),
11 (pts[2:, None] - f) / (pts[2:, None] - pts[1:-1, None])))
12 logmel = np.log(power @ H.T + 1e-10) # (T, 40)
13 n, k = np.arange(n_ceps)[:, None], np.arange(n_mels)[None]
14 dct = np.sqrt(np.where(n == 0, 1, 2) / n_mels) * np.cos(np.pi * n * (k + 0.5) / n_mels)
15 c = logmel @ dct.T # DCT-II, keep 13
16 c *= 1 + (lifter / 2) * np.sin(np.pi * np.arange(n_ceps) / lifter)
17 c -= c.mean(axis=0) # CMN
18 def delta(c, N=2):
19 p = np.pad(c, ((N, N), (0, 0)), mode="edge")
20 T = len(c)
21 return sum(m * (p[N + m:N + m + T] - p[N - m:N - m + T])
22 for m in range(1, N + 1)) / (2 * sum(m * m for m in range(1, N + 1)))
23 d = delta(c)
24 return np.hstack([c, d, delta(d)]).T # (39, T)
25
26t = np.arange(16000) / 16000
27x = np.sin(2 * np.pi * 220 * t) * (1 + 0.5 * np.sin(2 * np.pi * 3 * t))
28print(mfcc(x).shape) # (39, 98)
29# librosa.feature.mfcc(y=x, sr=16000, n_mfcc=13) is similar but not identical:
30# Slaney filters, dB scaling, no pre-emphasis, lifter or CMN by default.
39-dim MFCCs in numpy: pre-emphasis, Hamming frames, HTK mel, DCT-II, lifter, CMN, deltas. Run with numpy 2.5.

Use when

  • +Compact: 13 numbers per 10 ms, nearly decorrelated, ideal for diagonal-covariance GMMs
  • +Separates vocal-tract envelope from pitch; CMN removes fixed channel effects
  • +Cheap and training-free

Avoid when

  • −Truncation discards detail that deep networks can use
  • −The DCT mixes all bands into each coefficient, so a local noise burst corrupts every one
  • −Not invertible to audio without the dropped coefficients and phase

Where it's used

Classic ASR

GMM-HMM and hybrid DNN-HMM recognisers (HTK, Kaldi recipes), where 39-dim MFCCs with CMVN were the default input

Speaker recognition

GMM-UBM and i-vector systems; MFCCs or log-mels remain common inputs to x-vector style embeddings

Small devices

keyword spotting and simple sound classifiers where 13–40 numbers per frame fit a tiny model

Check yourself

A recording passes through a microphone with a fixed frequency response. What happens to its MFCCs, and how is it removed?

Check yourself

Why do classic recognisers keep only about 13 of the 40 DCT coefficients?

Remember

  • ✓MFCC = DCT-II of log mel energies, keep c0…c12c_0\dots c_{12}; Davis and Mermelstein (1980).
  • ✓Pipeline: pre-emphasis 0.97 → 25 ms / 10 ms Hamming frames → |FFT|² → mel → log → DCT → lifter 22 → CMN → Δ, ΔΔ → 39 dims.
  • ✓The log makes source and filter additive; low cepstral orders = envelope (formants), high orders = pitch ripple.
  • ✓The DCT approximates PCA for correlated log-mel bands, which diagonal-covariance GMM-HMMs needed.
  • ✓Deep models learn from 80/128 log-mels instead; MFCCs remain for small, classical or Gaussian models.
← back to Deep Learning roadmap