ben ebsworth
ΩElectrical Engineering

FFT Spectrum

Real-time frequency analyzer with log-scale bins — sine, square, sawtooth, chirp waveforms.

knobs
knobs

A pure sine wave produces a single sharp peak in the frequency spectrum. All energy concentrated at one frequency.

The Core Idea

Every signal is a sum of sinusoids. The Fast Fourier Transform (FFT) is the algorithm that performs this decomposition — taking N time-domain samples and producing N frequency-domain bins, each representing the energy at a particular frequency. It's O(N log N) instead of the naive O(N²), which is the difference between "takes a second" and "takes a week."

The Mathematics

The Discrete Fourier Transform (DFT) maps N samples x[0], ..., x[N−1] to N frequency bins:

X[k] = Σₙ x[n] · e^(−j2πkn/N)     for k = 0, ..., N−1

Each X[k] is a complex number whose magnitude represents energy at frequency f = k·fs/N and whose phase represents timing.

The FFT exploits the periodicity of the complex exponential to factor the DFT into two half-size DFTs, then recurses. For a 1024-point FFT, that's 10,240 operations instead of 1,048,576 — a 100× speedup.

knobs

A square wave's spectrum shows odd harmonics (3f, 5f, 7f, ...) at 1/n amplitude.

Different waveforms, different spectra

Switch the waveform control to see the spectral signatures:

  • Sine: Single peak. All energy at the fundamental.
  • Square: Odd harmonics at 1/n amplitude. Sharp edges require many harmonics.
  • Sawtooth: All harmonics at 1/n. The richest spectrum.
  • Chirp: Frequency sweeps upward → energy spreads across a band.
knobs

Sine wave with heavy noise (−10 dB SNR). The peak is still visible — the FFT pulls signals out of noise.

Adding noise

The FFT is a powerful tool for detecting signals buried in noise. A single-frequency signal concentrates all its energy in one bin, while noise spreads evenly. The processing gain of an N-point FFT is approximately 10·log₁₀(N/2) dB — a 1024-point FFT gives ~27 dB of gain.

Windowing

In practice, signals don't start and stop cleanly at FFT boundaries. Spectral leakage occurs when the signal period doesn't align with the FFT length — energy smears across adjacent bins. Window functions (Hann, Hamming, Blackman) taper the edges to reduce leakage at the cost of slightly wider main lobes.

Further reading

  • Fast Fourier transform (Wikipedia)
  • Lyons, Understanding Digital Signal Processing — the most accessible DSP textbook.
  • Cooley & Tukey (1965), An Algorithm for the Machine Calculation of Complex Fourier Series.