D58 of 13
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

D5 · Lesson 8 · Spectrograms

Watching a spectrum change over time with the short-time Fourier transform, the window length that trades time resolution for frequency resolution, when two tones can be told apart, frames, hops and overlap, and reading wideband and narrowband spectrograms of speech

A single FFT of a whole song tells you which notes appear somewhere in it, but not when. A spectrogram slides a short window along the signal, takes an FFT of each slice, and stacks the spectra side by side as columns of color: time across, frequency up, loudness as brightness. Bird songs, speech, radar returns and engine vibrations all become pictures you can read. Every spectrogram involves one unavoidable choice, the window's length, because a short window sees quick changes but blurs frequency, and a long one sees fine frequency detail but blurs time.

  • The spectrum of two equal tones Δ hertz apart, seen through a Hann window of length T. Each tone appears as a main lobe about 2/T wide on each side.
  • With a long window the lobes are narrow and two separate peaks show; shorten it and they merge into one blur.
  • The readouts give the window's frequency resolution and time resolution. Their product never changes: that's the trade-off.

Predict

Two tones are 20 Hz apart. About how long must a Hann window be for the spectrogram to show them as two peaks?

Name it

The short-time Fourier transform

Multiply the signal by a window of length T starting at time tm, take the FFT, move the window by a hop H, repeat. Each FFT is a frame, a column of the spectrogram; there are 1/H frames per second. Hops shorter than T (overlap, typically 50 to 75%) give a smoother picture.

The trade-off

A window of length T gives bins 1/T apart, and its main lobe sets how close two tones can be and still appear separately:

  • rectangular window: tones more than about 1.36/T apart;
  • Hann window: more than about 2/T apart.

But anything that changes within T is averaged together. Time resolution times frequency resolution is fixed, ΔtΔf≈ constant: no window beats it, only chooses where to sit on it.

Speech

  • A wideband spectrogram (window about 3 to 5 ms, resolution a few hundred hertz) shows each glottal pulse as a vertical stripe and the formants, the vocal tract's resonances, as dark bands.
  • A narrowband spectrogram (window 20 to 40 ms, resolution tens of hertz) shows the individual harmonics of the voice's pitch as horizontal lines.

Speech recognizers typically use 25 ms frames every 10 ms.

Worked example

A speech recognizer at 16 kHz uses 25 ms frames every 10 ms. How many samples per frame, how far apart are the bins, and how many frames per second?

Show the solution
  1. Samples per frame. 0.025s×16000Hz=400 usually zero-padded to a 512-point FFT.
  2. Bin spacing. Before padding: 10.025s=40Hz
  3. Frame rate. 10.01s=100frames/s
  4. Overlap. Each 25 ms frame shares 15 ms with the next, an overlap of 60%.

Answer 400 samples per frame, bins 40 Hz apart, and 100 frames per second, overlapping by 60%.

Worked example

With a 50 ms Hann window, are tones 40 Hz apart resolved? With a rectangular window, how close could they be?

Show the solution
  1. Hann window. It resolves tones about 2/T apart: 20.05s=40Hz so 40 Hz is exactly the limit: the two lobes merge into a flat top with no dip.
  2. Rectangular window. One of the same length separates tones down to about 1.36/T apart, at the cost of much higher leakage: 1.360.05s=27Hz

Answer 40 Hz is exactly the Hann window's limit, so the tones merge; a rectangular window separates tones about 27 Hz apart.

Worked example

A chirp sweeps at 100 kHz per second. What window length keeps its spectrogram trace sharpest?

Show the solution
  1. Two kinds of smear. In a window T the chirp moves kT Hz, while the bins are 1/T wide.
  2. Match them. The smear is least when the two are equal: kT=1TT=1k=1105s=3.2ms
  3. Either side. Longer windows blur in frequency, shorter ones in time.

Answer a window of about 3.2 ms keeps the trace sharpest.

Check

How far apart are the bins of a 25 ms analysis window (without zero padding)?

Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.

Check

Two tones are 20 Hz apart. What's the shortest Hann window that shows them as separate peaks?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

Check

How many samples does a 25 ms frame hold at 8 kHz?

Check

A spectrogram hops 10 ms between frames. How many frames does it compute per second?

Check

A spectrogram uses 25 ms frames every 10 ms at 8 kHz.

(a)

How many samples per frame?

(b)

How far apart are its bins?

Write units the way you normally would: 1.5 Hz, 1500 mHz and 0.0015 kHz are the same answer.

Check

A chirp sweeps at 100 kHz per second.

(a)

What window length keeps its trace sharpest?

Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.

(b)

How wide are the bins then?

Explain why

Why can't a spectrogram have both sharp time resolution and sharp frequency resolution?

Practice

Keep practicing

8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.