HomeArticlesSignals & Telecom

FFT and Spectral Analysis: Turning Signals into Frequencies

How the Fast Fourier Transform decomposes a signal in O(N log N), why windowing prevents spectral leakage, and how the STFT builds a spectrogram out of shifting frequencies.

mysimulator teamUpdated June 2026≈ 8 min read▶ Open the simulation

Every signal is secretly a sum of sinusoids

Joseph Fourier's 1807 claim — that any periodic function can be written as a sum of sines and cosines of different frequencies — was controversial enough that it took decades to be accepted, and it now underlies almost every piece of signal-processing technology in existence. The Fourier transform takes a signal described in time and re-expresses it as a spectrum described in frequency: the same information, viewed from a different axis.

live demo · a composite waveform decomposed into its component frequencies● LIVE

For a discrete, sampled signal of N points, the Discrete Fourier Transform (DFT) computes the amplitude and phase of N frequency components:

X[k] = Σ (n=0 to N-1)  x[n] · e^(−i·2π·k·n/N)     for k = 0 .. N-1

x[n] = the sampled time-domain signal
X[k] = complex amplitude at frequency k/N cycles per sample
|X[k]| = magnitude (how much of that frequency is present)

Computed directly, this is an O(N²) operation — every one of N output bins sums N input samples. The Fast Fourier Transform (FFT), popularised by Cooley and Tukey in 1965 (though the trick dates to Gauss), recursively splits the sum into even- and odd-indexed halves, reusing shared sub-results, and gets the same answer in O(N log N). That difference is not academic: for a one-million-sample signal it's the difference between a trillion operations and about twenty million — the FFT is why real-time spectrum analysis, audio compression and software radio are possible at all on ordinary hardware.

The uncertainty principle you can't compute your way around

A DFT of N samples taken at sample rate fs resolves frequency in bins of width fs/N — so to pin down frequency finely you need a long window in time. But a long window blurs together events that happen at different times within it. This trade-off is fundamental, not an implementation detail: it's the signal-processing analogue of the Heisenberg uncertainty principle, and no amount of clever coding removes it. You can trade time resolution for frequency resolution, but you cannot have arbitrarily good amounts of both simultaneously.

Windowing: taming the leakage

The DFT implicitly assumes the sampled chunk repeats forever, wrapping seamlessly end to end. Real signals almost never do — chopping out a slice of a sine wave usually leaves a discontinuity at the seam, which the transform interprets as high-frequency content that isn't really there. This artefact is called spectral leakage, and it smears a sharp spectral line across many neighbouring bins.

Window functions — Hann, Hamming, Blackman and others — fix this by tapering the signal smoothly to zero at both edges of the chunk before transforming, trading a small amount of frequency resolution (a slightly wider main lobe) for a large reduction in leakage (much lower side lobes). Which window to use is a genuine engineering choice: a Hann window is a reasonable general default, while a flat-top window sacrifices frequency resolution for the most accurate possible amplitude reading of a known tone.

The spectrogram: watching frequency change over time

A single FFT gives you one static spectrum for one window of time — useless for a signal like speech or music whose frequency content is constantly shifting. The Short-Time Fourier Transform (STFT) solves this by sliding a windowed FFT along the signal, computing a fresh spectrum for each overlapping chunk, and stacking the results into a spectrogram: a 2D image with time on one axis, frequency on the other, and colour (or brightness) showing energy. Reading a spectrogram is how a phonetician sees vowel formants, how an astronomer spots a chirping gravitational wave, and how compression codecs decide which frequencies a human ear won't miss.

Frequently asked questions

Why is the FFT so much faster than computing the DFT directly?

The direct DFT recomputes overlapping sums from scratch for every output frequency, costing O(N²) operations. The FFT recursively splits the transform into even- and odd-indexed halves and reuses shared partial sums, cutting the cost to O(N log N) — a difference that becomes enormous for large signals.

Why can't I get both perfect time and perfect frequency resolution?

A short time window gives coarse frequency resolution because the DFT's bin width is inversely proportional to window length; a long window gives fine frequency resolution but blurs together events at different times within it. This trade-off is mathematically fundamental, similar in spirit to the Heisenberg uncertainty principle, not a limitation of any particular algorithm.

What does a window function actually fix?

The DFT assumes the analysed chunk repeats seamlessly forever, which introduces a false discontinuity at the chunk's edges unless the signal happens to complete whole cycles exactly within it. A window function tapers the signal's edges toward zero before transforming, greatly reducing that artificial discontinuity and the spectral leakage it causes.

Try it live

Everything above runs in your browser — open Spectral Analysis and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Spectral Analysis simulation

What did you find?

Add reproduction steps (optional)