What Are MFCCs? Turning Mel-Spectrum Energy into Speech Feature Coefficients
Learn how mel-frequency cepstral coefficients (MFCCs) transform frame-level mel-band energies through a logarithm and a discrete cosine transform, and why settings matter when comparing results.
Short answer
Mel-frequency cepstral coefficients (MFCCs) are audio features computed by taking the log of mel-band energies from short audio frames and applying a discrete cosine transform (DCT). They summarize each frame with a relatively small set of coefficients and have been used in speech recognition, but they are not phonemes or words; values depend on settings and implementation. Kaldi feature extraction librosa MFCC documentation
From waveform to MFCC
A common pipeline is:
Divide audio into short frames and apply a window to each.
Compute a spectrum with a Fourier transform.
Sum frequency-bin energy into mel bands with a mel filter bank.
Take the logarithm of each mel-band energy.
Apply a DCT to the log-mel values and retain a chosen number of coefficients.
Kaldi describes a typical example with 25 ms frames shifted every 10 ms, log mel energies, a cosine transform, and, for example, 13 retained coefficients. These are implementation conventions, not a fixed requirement for every model. Choices include preprocessing, mel-bin count and frequency range, energy handling, and cepstral liftering. Kaldi
MFCCs versus a mel spectrogram
A mel spectrogram lists mel-band energy or power for each time frame. MFCCs are coefficients obtained by applying a DCT to log-mel values. Both vary over time, but their vertical axes differ: mel bands versus cepstral coefficients. Do not interpret an MFCC coefficient index as a particular frequency band or phoneme.
The DCT and selection of some coefficients give a compact representation, but do not preserve every detail of the log-mel spectrum. MFCCs alone should not be assumed to reconstruct the original waveform.
Compute MFCCs in Python
Requirements: Python, librosa, and NumPy. Input y is mono audio and sr is its actual sample rate in Hz. The example returns 13 coefficients; frame and mel settings must match the data and trained model.
import librosa
y, sr = librosa.load("speech.wav", sr=None, mono=True)
features = librosa.feature.mfcc(
y=y, sr=sr,
n_mfcc=13,
n_fft=400,
hop_length=160,
n_mels=40,
)
print(features.shape) # (number of coefficients, time frames)These are example values. At 16 kHz, 400 samples equal 25 ms and a 160-sample hop equals 10 ms. sr=None preserves the file’s native sample rate in librosa. If a model expects another rate or channel count, follow its preprocessing requirements and keep MFCC settings identical in training and inference. librosa MFCC
What to check when comparing results
**Coefficient count:** Changing n_mfcc changes feature dimensions and which coefficients are discarded.
**Mel bands and frequency range:** n_mels, fmin, fmax, mel scale, and normalization affect the input energies and resulting coefficients.
**Frame settings:** Sample rate, FFT/frame length, window, hop, padding, and centering affect frames and values.
**Energy and normalization:** Implementations may differ in whether C0 or energy is used, DCT type, log reference, liftering, and speaker- or utterance-level normalization. Do not assume library defaults match a model; specify and align them.
**Multiple channels:** Downmixing to mono or processing channels separately can change features. Follow the model’s channel handling.
To compare two MFCC arrays, align the audio, sample rate, coefficient count, frame and mel settings, normalization, and implementation. Coefficients from different configurations are not directly interchangeable.