FFT visualizer

Build a signal from up to three sine waves plus noise, choose the FFT size and window, and see the amplitude spectrum in dB. The spectrum is window-compensated so a sine of amplitude A peaks near 20·log10(A) dB.

What to try

  • Put tone 2 at 1,005 Hz with N = 256: the two tones merge because the bin spacing (31.25 Hz) is too coarse.
  • Switch the window from Hann to Rectangular and watch the leakage skirts rise.
  • Set a tone above fs/2 and find where it lands.
  • Add noise, then double N: the noise floor drops by about 3 dB each time while the tone peak stays put.

How it works

The tool takes N samples at sample rate fs, multiplies them by the chosen window w[n], and computes the discrete Fourier transform with a radix-2 FFT:

\[X[k] = \sum_{n=0}^{N-1} w[n]\, x[n]\, e^{-j 2\pi k n / N}, \qquad k = 0, 1, \dots, N/2\]

Bin k sits at frequency k·fs/N, so the spacing between bins and the length of the analysed frame are:

\[\Delta f = \frac{f_s}{N}, \qquad T = \frac{N}{f_s}\]

For example, fs = 48 kHz and N = 1,024 give Δf = 46.875 Hz and a frame of 21.33 ms. To turn |X[k]| into the amplitude of a sine, the tool divides by the window’s sum and doubles every bin except DC and fs/2:

\[A[k] = \frac{2\,|X[k]|}{\sum_n w[n]}\]

This is why a sine of amplitude 1 shows a peak near 0 dB, whatever window you pick.

Leakage and choosing a window

If a tone does not fall exactly on a bin, its energy spreads into neighbouring bins. This is spectral leakage. A window tapers the frame’s edges to reduce the far-out spread (the sidelobes) at the cost of a wider main peak. The numbers below were computed with NumPy/SciPy for large N:

WindowHighest sidelobeMain lobe half-widthWorst-case scalloping lossNoise bandwidth (ENBW)
Rectangular−13.3 dB1 bin3.92 dB1.00 bin
Hann−31.5 dB2 bins1.42 dB1.50 bins
Hamming−42.7 dB2 bins1.75 dB1.36 bins
Blackman−58.1 dB3 bins1.10 dB1.73 bins
  • Rectangular (no window): sharpest peak, worst leakage. Fine when tones sit exactly on bins.
  • Hann: a good default for general measurements.
  • Hamming: lower first sidelobe than Hann, but its far sidelobes fall off more slowly.
  • Blackman: use it to see a weak tone next to a strong one, accepting a wider peak.

Resolution: more samples, not more zeros

Two tones can only be separated if they are more than a few bins apart, and the bin spacing is set by how long you record: Δf = 1/T. Tones 5 Hz apart need a frame of at least 1/5 s, and roughly twice that with a Hann window. Zero-padding (appending zeros before the FFT) draws a smoother curve, but it does not add information, so it cannot separate tones that a shorter recording merges.

FAQ

Why is my peak lower than the tone’s amplitude?

The tone probably falls between two bins. The drop is called scalloping loss and can reach 3.92 dB with no window or 1.42 dB with Hann. Choose N so the tone lands on a bin, or read the peak height with a flat-top window for accurate amplitudes.

Why does the FFT size have to be a power of two?

This tool uses a radix-2 FFT, which works on lengths 2, 4, 8, … and is simple and fast. Other FFT algorithms handle any length, but powers of two remain the most common choice on embedded processors (for example in CMSIS-DSP).

Why does the noise floor drop when I increase N?

White noise spreads its power over all bins. Doubling N halves the bandwidth of each bin, so each bin holds about half the noise power: a 3 dB drop. A sine’s energy stays concentrated in one bin, so the tone stands further above the noise.

What is the difference between amplitude and power spectrum?

This tool shows amplitude, so a sine of amplitude A appears at 20·log10(A) dB. A power spectrum squares the magnitudes; in dB the shape is the same but scaling conventions (per bin or per hertz) differ between tools.

Related lessons: how the radix-2 FFT works, the short-time Fourier transform and running an FFT on a Cortex-M55.

References

  • Oppenheim, A. V. & Schafer, R. W., Discrete-Time Signal Processing, 3rd ed., Pearson, 2010, chapter on Fourier analysis of signals using the DFT.
  • Lyons, R. G., Understanding Digital Signal Processing, 3rd ed., Prentice Hall, 2011, chapters on the DFT and the FFT.
  • Harris, F. J., “On the use of windows for harmonic analysis with the discrete Fourier transform,” Proceedings of the IEEE, 66(1), 1978.
Esc