The STFT shows how the frequency content of a signal changes over time. It cuts the signal into short overlapping frames, multiplies each frame by a window, and takes the DFT of each frame. Shown as power in dB, the result is a spectrogram. It builds on the Discrete Fourier Transform (DFT).

Definition

  • is the frame length (the FFT size), is the hop between frames, is the window
  • is the frame index (time), is the frequency bin
  • is the spectrogram in dB, and the small avoids

Steps

In order:

  • cut the signal into frames of samples, each starting samples after the last
  • optionally subtract each frame's mean to remove any DC that is left
  • multiply each frame by a window, which reduces spectral leakage
  • FFT each frame, take the squared magnitude, convert to dB
  • stack the frames side by side: one axis is time, the other is frequency

Resolution Trade-Off

  • a longer frame gives finer frequency resolution but blurs fast changes in time
  • a shorter frame gives sharp timing but coarse frequency
  • you cannot have both, which is a form of the time and frequency uncertainty principle
  • example: at MHz with and , each bin is about 48.8 kHz wide and each frame step is about 10.24 µs

Overlap And Frame Count

Why overlap:

  • the window fades the ends of each frame, so samples near the ends count less
  • overlapping frames (50% or 75% is common) give every sample good weight in some frame

Frame count:

  • to get exactly 1024 frames of 1024 samples with hop 512, you need samples

Complex Input

  • with complex samples, positive and negative frequencies are different, so the FFT covers to
  • fftshift moves 0 Hz from the first bin to the centre, so the picture runs from the lowest to the highest frequency

Uses

  • speech and music analysis (often on a mel scale)
  • radio signal analysis, for example seeing WiFi bursts and Bluetooth hops in a 2.4 GHz capture
  • machine vibration monitoring
  • a spectrogram turns a signal into an image, so image models such as CNNs can classify it