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

S7 · Lesson 30 · The short-time Fourier transform

Spectra that change with time, window length against time and frequency resolution, hop size and overlap, spectrograms, and perfect reconstruction by overlap-add

Speech, music, radar returns and machine vibration all have spectra that change from moment to moment, and a single FFT of the whole recording averages that change away. The short-time Fourier transform slides a window along the signal and takes an FFT of each windowed piece, giving a spectrum for every moment: a spectrogram. The window length decides what can be seen. A long window resolves close frequencies but blurs events in time; a short one catches fast changes but smears frequencies. Choosing it well is a quantitative trade, and for some signals there's an exact best length.

  • The frequency spread of a linear chirp sweeping R Hz per second, seen through a Hann window of length T: the sweep during the window, RT (dotted), plus the window's own resolution, 2/T (dashed), against T.
  • Short windows are limited by their resolution and long ones by the chirp's motion; the total (solid) is smallest at T=2/R.
  • For a chirp sweeping 1 kHz per second that's a 44.7 ms window, with a spread of 89 Hz. Faster chirps need shorter windows and blur more.

Predict

A speech analyzer at 16 kHz uses 25 ms Hann windows every 10 ms. How finely can it resolve frequencies, and how many spectra does it produce per second?

Name it

Definition

X[n,k]=∑m=0L−1x[nR+m]w[m]e−j2πkm/N

a window of L samples, hopped by R samples, each frame transformed by an N-point DFT (N ≥ L). Its squared magnitude, plotted against time and frequency, is the spectrogram.

Resolution

  • Frequency: about fs/L for a rectangular window, 2f_s/L for Hann and Hamming (lesson 29).
  • Time: about the window length, T=L/fs.
  • Their product can't be made small: Δt·Δf is at least of order 1, the time–bandwidth (uncertainty) principle. A wideband spectrogram (short window) shows pitch pulses in time; a narrowband one (long window) shows individual harmonics.
  • For a chirp sweeping R Hz/s, the spread is about RT+2/T with a Hann window, smallest at T=2/R, where it's 22R.

Hop size and reconstruction

  • The hop R sets the frame rate fs/R. With a real input, the STFT produces about N/(2R) complex values per input sample, so it's redundant unless R = N.
  • Overlap-add synthesis: inverse-FFT each frame, then add the frames at their positions. The original returns exactly if the shifted windows sum to a constant: ∑nw[m−nR]= const (the COLA condition). The periodic Hann window at 50% overlap sums to exactly 1; Hamming at 50% sums to 1.08.
  • Modifying the frames before synthesis gives time-varying filtering, noise reduction and time-scale changes.

Worked example

A chirp sweeps 1 kHz per second. What window length gives the sharpest spectrogram, and how sharp is it?

Show the solution
  1. Best window length. T=2/1000s=44.7ms
  2. The window's resolution. Δf=20.0447Hz=44.7Hz
  3. The chirp's motion. During the window the chirp moves Δf=1000×0.0447Hz=44.7Hz The two contributions are equal at the optimum.
  4. Total spread. Δf=44.7+44.7Hz=89.4Hz
  5. Away from the optimum. Halving or doubling T raises it to 112 Hz.

Answer a 44.7 ms window, which smears the chirp over 89.4 Hz.

Worked example

Show that the periodic Hann window satisfies the COLA condition at 50% overlap for N = 8.

Show the solution
  1. The window. w[m]=0.5−0.5cos⁡(2πm/8)
  2. Add a frame 4 samples on. w[m]+w[m+4]=1−0.5[cos⁡(πm/4)+cos⁡(πm/4+π)]=1 for every m, since the two cosines cancel.
  3. Conclusion. Frames hopped by 4 therefore add back to exactly the original signal.

Answer w[m]+w[m+4]=1 for every m, so the periodic Hann window satisfies COLA at 50% overlap.

Worked example

Speech sampled at 16 kHz has a pitch of 120 Hz. Compare 5 ms and 40 ms Hann windows.

Show the solution
  1. The 5 ms window. That's 80 samples, with about Δf=2fsL=400Hz of frequency resolution and 5 ms of time resolution.
  2. What it shows. The harmonics, 120 Hz apart, blur together, but each glottal pulse (every 8.3 ms) shows as a vertical stripe.
  3. The 40 ms window. That's 640 samples, with 50 Hz resolution: the harmonics separate into horizontal lines, but the pulses merge.
  4. In practice. Speech analysis uses both: wideband for timing, narrowband for pitch.

Answer the 5 ms window (400 Hz resolution) shows each pitch pulse but blurs the harmonics; the 40 ms window (50 Hz) resolves the harmonics but merges the pulses.

Check

A 25 ms window at 8 kHz holds how many samples?

Check

Roughly what frequency resolution does a 25 ms Hann window give?

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

Check

An STFT at 16 kHz hops 64 samples per frame. How many frames per second?

Check

A chirp sweeps 5000 Hz per second. What Hann window length shows it most sharply?

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

Check

A chirp at 5000 Hz/s is analyzed with a 5 ms Hann window. Roughly how wide does it appear?

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

Check

A real signal's STFT uses 1024-point FFTs with a hop of 128. How many unique complex values does it produce per input sample?

Check

A 20 ms Hann window analyzes 8 kHz audio whose harmonics are 200 Hz apart.

(a)

How many samples does the window hold?

(b)

Roughly what frequency resolution does it give?

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

Check

A chirp sweeps R Hz per second through a Hann window T seconds long.

Step 1

Roughly how wide does it appear?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

Why can't a spectrogram be sharp in both time and frequency at once?

Practice

Keep practicing

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