The FFT Meets Time
So far in Module 6 we have treated the FFT as a tool that transforms an entire signal block into its frequency content. That works beautifully for stationary signals — signals whose frequency content doesn't change over time. But most real-world signals are non-stationary: speech rises and falls in pitch, a guitar note decays, a radar return sweeps across frequencies, an engine vibration shifts as RPM changes.
To capture how frequency content evolves with time, we need to repeatedly apply the FFT to short, overlapping segments of the signal. This technique is called the Short-Time Fourier Transform (STFT), and it is the engine behind every spectrum analyzer, spectrogram display, and real-time audio monitor you have ever encountered.
The Short-Time Fourier Transform
The STFT is conceptually simple: slide a window of length N across the signal, multiply each windowed segment by a window function (to reduce spectral leakage), compute the FFT, and store the result. Stacking these spectra over time produces a 2-D representation: frequency on one axis, time on the other.
The magnitude squared |X[m, k]|² is the spectrogram — a power map showing which frequencies are active at each point in time. A logarithmic (dB) scale is almost always used to compress the wide dynamic range of real signals.
Three Parameters That Control Everything
Every STFT has three design choices, and understanding their trade-offs is the heart of real-time spectrum analysis:
| Parameter | Symbol | Controls | Typical Range |
|---|---|---|---|
| Frame size | N | Frequency resolution: Δf = f_s / N | 256 – 8192 |
| Hop size | R | Time resolution: Δt = R / f_s | N/4 – N/2 |
| Window function | w[n] | Leakage vs. resolution trade-off | Hann, Hamming, Blackman |
You cannot simultaneously have perfect time resolution and perfect frequency resolution — this is the time-frequency uncertainty principle. A short frame (small N) gives fine time resolution but coarse frequency bins. A long frame (large N) gives fine frequency resolution but poor time resolution. The hop size R controls how often you update the display — it can be set independently of N, but the frame length ultimately determines both resolution axes.
Short frame → good time, coarse frequency. Long frame → fine frequency, poor time.Overlap and the Hann Window
In practice, frames typically overlap by 50–75%. With a hop size R = N/2, consecutive frames share half their samples. Overlap serves two purposes: it increases the time resolution of the spectrogram display, and — when used with certain windows — it enables perfect reconstruction of the original signal (useful for audio processing, not just analysis).
The Hann window (raised cosine) is the most common choice for real-time spectrum analysis. It tapers smoothly to zero at both ends, eliminating the abrupt edge that causes severe leakage with a rectangular window. With 50% overlap, consecutive Hann-windowed frames sum to a constant — the constant overlap-add (COLA) condition that guarantees perfect reconstruction.
Building a Real-Time Spectrum Analyzer
A real-time spectrum analyzer processes a continuous audio or RF stream and updates a frequency display fast enough to appear live. The standard architecture in software is:
In a browser, the Web Audio API's AnalyserNode performs exactly these four steps internally — it maintains a ring buffer, applies a Blackman window, computes the FFT, and provides getByteFrequencyData() returning log-magnitude bins ready for canvas rendering.
Averaging and Peak Hold
Raw FFT output is noisy — individual frames bounce around even for a steady sine wave, because of noise and the finite frame length. Two display techniques combat this:
Waterfall Displays
A waterfall (or spectrogram) display scrolls time across one axis while frequency occupies the other, with colour or intensity encoding power. Each new STFT frame adds one row (or column) to the display. The result is a 2-D "movie" of the spectrum that reveals structure invisible in a single-frame view: chirps appear as diagonal lines, harmonics as parallel horizontal bands, interference as vertical streaks.
Waterfall displays are standard in:
- Software-defined radio (SDR) — monitoring wideband RF spectrum for signals, interferers, and occupancy
- Audio engineering — identifying room modes, reverb tails, and harmonic content in recordings
- Vibration analysis — tracking resonance frequencies in rotating machinery as load changes
- Medical acoustics — visualising speech patterns, breathing sounds, and ultrasound Doppler data
Audio speech: N = 512–1024, hop = N/2, Hann window. Phonemes last ~50–100 ms so time resolution of ~10 ms (N=512 at 48 kHz) captures transitions well.
Music/tonal analysis: N = 2048–4096, hop = N/4. Fine frequency resolution reveals partials; 75% overlap gives smooth visual motion.
SDR wideband scanning: N = 1024–4096, hop = N (no overlap). Throughput matters more than reconstruction; update rate = f_s / N.
Vibration monitoring: N = 4096–8192, hop = N/2. Long frames resolve closely spaced mechanical harmonics (often only a few Hz apart).
Computational Budget
A real-time analyzer must complete one FFT frame before the next hop arrives. The compute budget per frame (in seconds) is simply R / f_s. For audio at 48 kHz with N = 1024 and R = 512, the budget is 512 / 48000 ≈ 10.7 ms. A 1024-point real FFT takes under 0.1 ms on a modern CPU — so there is enormous headroom for averaging, display rendering, and peak hold logic.
For wideband SDR applications processing tens or hundreds of MHz of bandwidth, the budget shrinks dramatically and GPU-accelerated FFTs (cuFFT) become necessary. A GPU can run thousands of 1024-point FFTs in parallel, enabling real-time spectrograms of signals that would overwhelm any CPU.
- The Short-Time Fourier Transform (STFT) applies the FFT to overlapping windowed frames, producing a time-frequency map of how spectral content evolves.
- Frame size N controls frequency resolution (Δf = f_s / N); hop size R controls time resolution (Δt = R / f_s). Making one finer coarsens the other — the time-frequency uncertainty principle.
- The Hann window is the standard choice for real-time analysis: low side lobes, smooth tapering, and it satisfies the COLA condition at 50% overlap for perfect reconstruction.
- A real-time spectrum analyzer captures samples into a ring buffer, applies the window every R samples, computes the FFT, and renders the dB-magnitude spectrum — repeating at the hop rate.
- Exponential smoothing reduces display noise; peak hold reveals transient peaks. Both are applied after the FFT, not before.
- Waterfall displays scroll time on one axis and frequency on the other, revealing time-varying structure (chirps, harmonics, interference) that a single-frame spectrum cannot show.
- Modern CPUs have enormous compute headroom for audio-rate STFT; GPU-accelerated FFTs (cuFFT) are required for wideband SDR applications processing hundreds of MHz.