Skip to content

Spectrogram

A picture of sound: time runs left to right, pitch runs bottom to top, and brightness shows how loud each frequency is at each moment.

Also Mel spectrogram · log-Mel · STFT · short-time Fourier transform · frequency

Fig. / How it works
WaveformWaveformCut into short windowsCut into short windowsFourier transform eachFourier transform eachFrequencies over timeFrequencies over time
Role · kind
DataConcept
Level
Beginner

Like sheet music drawn by the sound itself. Low notes appear near the bottom, high notes near the top, and loud notes glow brightly.

Where it fits

+All relationships as a list

See it on the full map

Try it

See what sound looks like
Loading interactive widget…
TakeawayA spectrogram turns sound into a picture of pitch over time, which is what speech and audio models actually read. Window size trades sharp timing against sharp pitch.

How it works

Any sound can be described as a mix of pure tones (sine waves) at different frequencies. The Fourier transform finds that mix. But speech and music change constantly, so we compute it on short slices instead:

  1. Cut the waveform into short, overlapping windows (often about 25 milliseconds).
  2. Compute the frequency content of each window.
  3. Stack the results side by side.

The result is a grid: time across, frequency up, and loudness as color. A whistle is a thin line, a chord is several parallel lines, a drum hit is a vertical smear, and noise is a gray fog.

Two tweaks make spectrograms match human hearing. The Mel scale spaces frequencies the way we perceive pitch (we hear the difference between 100 and 200 Hz far more clearly than between 10,000 and 10,100 Hz), and taking the log of the power matches how we perceive loudness. That “log-Mel spectrogram” is what Whisper and most speech recognition models read.

There is a built-in trade-off: longer windows separate frequencies better but blur when things happen; shorter windows do the opposite.

The math

For a signal x[n]x[n] and window w[n]w[n] of length NN, frame mm with hop HH:

X[m,k]=∑n=0N−1x[n+mH] w[n] e−2πikn/NX[m, k] = \sum_{n=0}^{N-1} x[n + mH]\, w[n]\, e^{-2\pi i k n / N}

The spectrogram is ∣X[m,k]∣2|X[m, k]|^2, usually shown on a log (decibel) scale.

Everyday use cases

  • Case 01

    Speech recognition input

    Whisper and most speech models read log-Mel spectrograms, not raw audio.

  • Case 02

    Song identification

    Music recognition apps match distinctive peaks in a recording's spectrogram.

  • Case 03

    Bird and whale research

    Biologists spot and classify calls by their shapes in spectrograms.

Strengths, weaknesses and when to use it

Strengths

  • Turns sound into an image-like grid that CNNs and Transformers handle well.
  • Makes pitch, rhythm and timbre visible.

Weaknesses

  • Trade-off between time and frequency detail (window size).
  • Discards phase, so turning a spectrogram back into audio needs extra work.

When to use itAs the default first step for almost any audio model.

Check yourself

  1. Q01

    In a spectrogram, what does the vertical axis show?

    Show answer

    B: Frequency (pitch)

  2. Q02

    What happens if you use a longer analysis window?

    Show answer

    A: Sharper frequency detail but blurrier timing

Go deeper