Spectrograms

A spectrogram is a plot that allows us to visualize the time-dependent frequency content of sound. It shows which frequencies are present, how strong each one is, and how these change over time.

To build one, the sound is chopped into short slices (windows) and the frequency content of each slice is found through a Fourier transform. Each frequency spectrum is mapped onto a column of colors (encoding the “strength” of each frequency), with low frequencies at the bottom and high ones at the top. These columns then scroll past as time progresses.

Altogether, we are left with an animated graph:

  • the horizontal axis is time, with the present moment at the right edge
  • the vertical axis is frequency, low at the bottom
  • color is level, how strong that frequency was at that moment

Everything below happens inside your browser. No audio is uploaded, stored, or recorded.

Live Spectrogram

Sing, whistle, or play an example sound and watch its frequencies scroll past. Turn on measurements to read exact values.

Things worth trying:

  • Whistle, and slide your pitch up and down
  • Say “ssss”, then “ahhh”
  • Play the harmonic stack and find the relationship between the prominent frequencies
  • Listen to some birdsong

There are many patterns to be found in natural (and synthesized) sounds. A steady horizontal line is a constant tone with one frequency. A collection of evenly spaced lines is known as a harmonic stack. A vertical streak is a click, handclap, or some other percussive sound.

Note that many instruments, including your voice, do not produce a single frequency. They often produce a harmonic stack: a fundamental frequency f1f_1 together with harmonics at integer multiples 2f1,3f1,4f1,…2f_1, 3f_1, 4f_1, \ldots. A first-year physics course will usually explain the mechanism by which these harmonics are produced.

The quietest sound you can hear and a sound loud enough to hurt differ in amplitude by a factor of around a million. With a linear “loudness scale”, it is difficult to visually distinguish between quiet and loud. So the scale is logarithmic, measured in decibels:

L=20log⁡10 ⁣(AA0).L = 20\log_{10}\!\left(\frac{A}{A_0}\right).

Every 20 dB20\ \text{dB} is a factor of ten in amplitude. In the spectrogram, the Floor control sets where the color scale bottoms out: raise it to remove background noise, leaving only the strong components.

Likewise, the vertical frequency axis is also logarithmic. Equal frequency ratios take equal space, so every octave is the same height and a musical interval becomes a fixed distance no matter where on the display it sits.

The Gabor Limit

The spectrogram does not consider the entire data set at once. It looks at NN samples (the window) at a time, taken at a sample rate fsf_s. That window lasts

Δt=Nfs,\Delta t = \frac{N}{f_s},

and it cannot distinguish two frequencies closer together than

Δf=fsN.\Delta f = \frac{f_s}{N}.

Multiply them and the NN and fsf_s both cancel:

Δf Δt=1.\Delta f\,\Delta t = 1.

A short window pins down when something happened at the cost of frequency resolution. A long window better resolves the frequency content but loses temporal resolution.

This is the Gabor limit, and it is not a limitation of this particular analyzer or of computers in general. It is a theorem about signal processing, and it is the same mathematics that reappears later as the uncertainty principle in quantum mechanics.

Problem Solving

Reading a Harmonic Stack

Problem

A frozen spectrogram shows bright horizontal lines at 165 Hz165\ \text{Hz}, 330 Hz330\ \text{Hz}, 495 Hz495\ \text{Hz}, and 660 Hz660\ \text{Hz}, and nothing below 165 Hz165\ \text{Hz}. What note is sounding?

Use

Harmonics sit at integer multiples of the fundamental,

fn=nf1,f_n = n f_1,

so the spacing between neighbouring lines is itself the fundamental.

Solve

The gaps are 330−165=165330 - 165 = 165, 495−330=165495 - 330 = 165, and 660−495=165 Hz660 - 495 = 165\ \text{Hz}. So f1=165 Hzf_1 = 165\ \text{Hz}, and the four lines are f1f_1 through 4f14f_1. Converting to a note,

n=69+12log⁡2 ⁣(165440)≈52,n = 69 + 12\log_2\!\left(\frac{165}{440}\right) \approx 52,

which is E3.

Check

The lines are equally spaced in hertz but not in ratio, so on the log axis they crowd together going up — the signature of one instrument rather than four unrelated tones.

Choosing a Window

Problem

Two tones 4 Hz4\ \text{Hz} apart are playing, slow enough that you hear them beat. The sample rate is fs=48 000 Hzf_s = 48\,000\ \text{Hz}. Will a 20482048-point window show them as two separate lines?

Use

Δf=fsN,Δt=Nfs.\Delta f = \frac{f_s}{N}, \qquad \Delta t = \frac{N}{f_s}.

Solve

Δf=48 0002048≈23.4 Hz,\Delta f = \frac{48\,000}{2048} \approx 23.4\ \text{Hz},

which is far coarser than the 4 Hz4\ \text{Hz} gap, so both tones land in the same resolution cell and paint a single thick line that pulses. Separating them needs

N≳fsΔf=48 0004=12 000N \gtrsim \frac{f_s}{\Delta f} = \frac{48\,000}{4} = 12\,000

samples, so even the 81928192-point window is not quite enough — and it already spans 8192/48 000≈0.17 s8192/48\,000 \approx 0.17\ \text{s}.

Check

The pulsing is the beat itself, showing up on the time axis precisely because the frequency axis could not hold it.

Spectrogram Checkpoint1 of 3

You switch the analyzer to a shorter window. What happens to the picture?