TL;DR
A mel spectrogram is a spectrogram whose frequency axis has been regrouped. Instead of one row per FFT bin, it has a few dozen bands, spaced evenly on the mel scale, which are narrow at low pitches and wide at high ones. Each band's energy is then log-compressed. The result is a compact grid of numbers over time and band that matches how hearing spaces pitch, and most speech and audio models take it as input.
Builds on: Time-Frequency Representation, Mel Scale, Logarithm · Leads to: speech recognition front ends
Where it's used
Speech recognition. Many speech recognisers turn audio into a log-mel spectrogram before any learning happens. Systems often use somewhere between 40 and 128 mel bands, a design choice that trades detail for size.
Music and sound classification. A model that labels a clip as "jazz" or "rain" sees a mel spectrogram as a picture, with time across and bands up. Convolutional networks can then read it the way they read an image, looking for local patterns that move through time.
Data augmentation for speech. SpecAugment trains speech models on mel spectrograms in which random blocks of time steps and of bands are masked. The model must then recognise the word from the parts it can still see.
How it works
Here is one tiny instance traced from start to finish. A single frame of sound has already been turned into a power spectrum, which is the strength at each frequency. There are four frequency points: 0, 700, 1,400 and 2,100 hertz, with powers 0, 4, 2 and 6.
- Start with a power spectrum on a linear axis. The values at 0, 700, 1,400 and 2,100 Hz are 0, 4, 2 and 6. Check: there is one number per frequency, and the spacing between them is equal in hertz.
- Place the band centres evenly on the mel scale. Convert 0, 700 and 2,100 Hz to mel with : 0, 781 and 1,562. Check: the gaps are 781 and 781, equal in mel, although the hertz gaps are 700 and 1,400.
- Build two triangular filters. Filter 1 rises from 0 Hz to a peak at 700 Hz and falls back to zero at 2,100 Hz. Filter 2 rises from 700 Hz to a peak at 2,100 Hz and falls to zero at 4,900 Hz. Weights change linearly in mel. Check: each filter is zero at the centres of its neighbours.
- Read the filter weights at 1,400 Hz. In mel, 1,400 Hz is . Filter 1 gives , and filter 2 gives . Check: the two weights add to 1.
- Take the weighted sums. Filter 1 gives . Filter 2 gives . Check: each filter used only its own weights.
- Take the logarithm. The natural logs are and . Check: the output for this frame is two numbers, , replacing four frequency values.
The diagram shows the whole pipeline for a clip, with each frame passing through the same steps.
flowchart LR A[Audio samples] --> B[Frames with a window] B --> C[Power spectrum of each frame] C --> D[Triangular mel filters] D --> E[Weighted sum per band] E --> F[Logarithm] F --> G[Mel spectrogram: time by band]
The math
The mel value of a frequency in hertz is
with inverse . A bank of triangular filters is built on mel centres that are evenly spaced. The mel spectrogram is
Step 1 in symbols: the power spectrum
For frame , the power at bin is . In the walkthrough, the four powers are at hertz.
Step 2 in symbols: centres on the mel axis
The centres are for , and each has a hertz value . In the walkthrough, mel, which gives the hertz centres , , and . Check: , and .
Step 3 in symbols: triangular weights
With , the weight of filter at frequency is a linear interpolation on the mel axis:
The weight is 1 at the centre and falls to 0 at the neighbouring centres. At 1,400 Hz, , so and .
Step 4 in symbols: the band energy
The energy in band is the weighted sum . In the walkthrough, and .
Step 5 in symbols: the logarithm
The output is , giving and . Taking the logarithm compresses the range, so that a few loud bands do not drown out the rest. In practice a small floor is added before the logarithm to keep it finite when a band is silent.
Worked examples
We want the mel value of 1,000 Hz, and the hertz value of 500 mel.
- Compute . The ratio is , so the argument is .
- , and . So 1,000 Hz is about 1,000 mel.
- Invert 500 mel: . The exponent is , and .
- Hz.
- Interpretation: 500 mel is about 391 Hz, so a band centred at 500 mel sits well below the midpoint of the hertz range, as the compression at high pitch predicts.
Speech is sampled at 16 kHz. Each frame is 25 ms long, the frames are 10 ms apart, the FFT length is 512, and there are 80 mel bands. The numbers are typical choices, not those of any one system.
- Samples per frame: .
- FFT bins: , covering 0 to 8,000 Hz.
- Frames per second: . A 10-second clip has about frames.
- Output size: numbers, from FFT values.
- Interpretation: each frame shrinks from 257 bins to 80 bands, a ratio of about 3.2, while the time resolution of 10 ms stays the same.
Try it: a 6-second clip uses the same settings. How many numbers does its mel spectrogram hold? Answer: frames, and numbers.
A front end uses 80 mel bands from 0 to 8,000 Hz. That needs 82 mel points, from the lowest to the highest, which are 81 gaps. The total mel range is , so the gap is mel.
- The first centre is at 35.1 mel, which is Hz. The second is at 70.2 mel, which is about 45 Hz. The bands at the bottom are about 23 Hz apart.
- The last centre is at mel, which is about Hz. The top edge is 8,000 Hz.
- The gap at the top is about Hz.
- Interpretation: near the top, the bands are more than ten times wider in hertz than at the bottom. The bank spends its resolution on the low pitches, where speech and music carry most of their detail.
Try it: the same range with 40 bands. What is the gap in mel? Answer: mel.
Common mistakes and tradeoffs
It is tempting to think a mel spectrogram is a different kind of transform from a spectrogram. In fact it is a spectrogram with its frequency axis regrouped. The framing, the windowing and the Fourier transform are the same, and only the bands and the logarithm are added.
It is tempting to think the mel scale is exactly what human hearing does. In fact it is an approximation fitted to pitch experiments from the 1930s. Real perception also depends on loudness and context, and other scales are used when those matter.
It is tempting to think that the scale formula is fixed. In fact there are several. The common form is one choice, and some toolkits use a version that is linear below 1 kHz and logarithmic above it. Check which one a model was trained with before using its features.
It is tempting to think that more bands are always better. In fact the bands at the bottom become wide in hertz when the count is small, so a low, precise tone smears across one band. A dense bank also produces highly overlapping, redundant features.
It is tempting to think the logarithm can be skipped. In fact a linear mel spectrogram is dominated by its loudest bands, and most learning systems train better with the log, which also matches the way loudness is perceived.
When to use it. Use it for speech, music and general sound, where the content is pitch patterns that change over time, and where a learned model will read the result.
When not to use it. Avoid it when the exact frequency matters, such as measuring a precise hum or tuning an instrument. A linear-frequency spectrogram with a longer window resolves those.
Alternatives. The table compares the common front ends.
| Front end | Frequency axis | Typical use |
|---|---|---|
| Linear spectrogram | Even bins in hertz | Precise frequency analysis, such as hum or tone detection |
| Log-mel spectrogram | Mel bands, log energy | Speech and audio models that learn from the picture |
| Mel-frequency cepstral coefficients | Mel bands, then a further transform | Classic speech systems that use a compact set of numbers |
| Learned filter bank | Filters learned from the data | Models that take the waveform directly |
History
The mel scale comes from listening experiments in the 1930s, in which people judged when pitches were equally spaced. Its name comes from "melody". The scale was a measurement of perceived pitch, and it stayed a research tool for decades.
In 1980 Steven Davis and Paul Mermelstein used mel-spaced filters to build a compact set of features for recognising words, now known as mel-frequency cepstral coefficients. Those features became a standard front end for speech recognition for a long time. As neural networks grew able to learn from images, the log-mel spectrogram itself became the common input, because a convolutional model can learn its own features from the picture. The mel spectrogram is now the usual input to many speech and audio systems.
Recap
- A spectrogram gives power over time and frequency, one bin per FFT frequency.
- A mel spectrogram groups those bins into bands whose centres are evenly spaced on the mel scale, using triangular weights.
- The band energies are log-compressed, which gives a compact grid over time and band.
- The bands are narrow at low pitches and wide at high ones, which keeps detail where speech and music carry most of their information.
- Read next: Mel Scale for the scale itself, Automatic Speech Recognition for the main use, and SpecAugment for how the picture is augmented during training.