How it works
The Discrete Fourier Transform (DFT) maps N samples x[0], …, x[N−1] to N complex bins:
X[k] = Σₙ x[n] · e^(−j2πkn/N) for k = 0, …, N−1
Each X[k] is a complex number: its magnitude is the energy at frequency f = k·fs/N, its phase the timing. Computed directly that double loop is N² multiply-adds. The FFT instead exploits the periodicity of the complex exponential to split each DFT into two half-size DFTs and recurses — the Cooley–Tukey radix-2 trick. This visualiser runs a 2048-point FFT (11 recursion stages) over a 48 kHz signal, so it does ~22,500 operations instead of ~4.2 million per frame — roughly 180× fewer.
The resulting 1024 magnitude bins are folded into 256 bars spread on a log frequency axis from 20 Hz to 20 kHz, which is why a 440 Hz tone and its harmonics sit where your ear would put them.
Pulling signals out of noise
A periodic signal piles all its energy into a few bins; broadband noise spreads thinly across every bin. So the FFT acts as a matched comb — even when the time-domain trace looks like static, the peak still pokes above the floor. The processing gain of an N-point FFT is about 10·log₁₀(N/2) dB, so this 2048-point transform buys roughly 30 dB. The catch is spectral leakage: when a tone's period doesn't divide the window evenly, its energy bleeds into neighbours. A tapering window fixes most of it — this renderer applies a Hann window before every transform, trading a slightly wider peak for far less smearing.
The knobs
- Waveform — choose the source signal: sine, square, sawtooth, triangle, two tones, or an upward chirp.
- Noise (dB) — adds white noise from −60 dB (effectively clean) up to 0 dB, where the signal is buried. Watch how high you can push it before the peak vanishes.