FFT Frequency Analyzer
Configurable Fast Fourier Transform with selectable window functions (Rectangle, Hann, Hamming, Blackman, Blackman-Harris, Flat-top), magnitude & phase display, controllable bin resolution, and real-time peak detection. Educational and measurement-grade — every step is exposed.
Top 5 spectral peaks
| # | Frequency | Magnitude | Phase | Note |
|---|---|---|---|---|
| Start listening to detect peaks. | ||||
Controls
About the FFT & Window Functions
The Fast Fourier Transform (FFT) is the workhorse of audio analysis: it takes a block of N time-domain samples and returns N/2 complex frequency-domain values, each representing the amplitude and phase of one frequency component. The big choice you make every time you run an FFT is the window function — how you shape the time-domain samples before the transform. Picking the right window is half the art of spectral analysis.
Why windows exist (spectral leakage)
The FFT mathematically assumes its input is one period of an infinitely-repeating signal. Real signals don't periodically align to the FFT block boundary, so the FFT sees a discontinuity at the wrap-around point — and that discontinuity smears each true frequency line into a wide skirt of false sidebands. This artifact is called spectral leakage. A window function multiplies the input by a smooth envelope that tapers to zero at the edges, eliminating the discontinuity at the cost of slightly widening the true frequency lobe.
The four key window properties
Every window trades off four characteristics:
- Main-lobe width — how wide the peak around a single tone is. Narrower = better frequency resolution (you can separate close tones). Rectangle wins; Flat-top loses.
- Side-lobe rejection — how much the leakage skirts are attenuated. Higher rejection = weak tones aren't hidden by strong ones nearby. Blackman-Harris wins; Rectangle loses.
- Amplitude accuracy — how accurately the peak height matches the true tone amplitude. Flat-top is engineered for this; others can be off by 1.5 dB depending on where the tone lands relative to bin centers.
- Coherent gain (CG) — the DC gain of the window. Used to normalize back to true amplitude.
When to use which window
- Rectangle — never (unless you specifically want the rawest output for debugging or for a signal you know is periodic in the FFT block, e.g., FFT-synthesized tones).
- Hann — default general-purpose choice. Reasonable side-lobe rejection (-31 dB), moderate main lobe. 90% of real-world FFT work uses Hann or Hamming.
- Hamming — slightly better near-in side-lobe than Hann but worse far-out. Original telecom standard.
- Blackman — sharper side-lobe rejection (-58 dB) at the cost of a wider main lobe. Use when weak tones near strong tones matter.
- Blackman-Harris — extreme rejection (-92 dB) for highly contaminated spectra. Wide main lobe; only use if dynamic range matters more than resolution.
- Flat-top — for amplitude measurement: peaks match the true tone level to within ~0.01 dB regardless of where the tone falls between bins. Very wide main lobe; useless for resolving close tones.
FFT size and bin resolution
The frequency resolution is Δf = sample_rate / N. At 48 kHz sample rate: N=4096 → 11.72 Hz/bin, N=16384 → 2.93 Hz/bin. Bigger N → finer resolution but more compute (and slower frame rate, since you need to wait longer for a full FFT block). For typical audio work, N=4096 to 8192 is the sweet spot. For very fine pitch work (instrument tuning, room modes below 100 Hz), use N=16384 or larger.
Magnitude and phase
Each FFT bin is a complex number; the magnitude tells you "how much energy is at this frequency", the phase tells you "what timing relationship" each frequency has relative to the start of the FFT block. For most audio work the magnitude is all that matters (since perception is mostly phase-insensitive). Phase shows up when comparing channels (stereo phase coherence), debugging filter group delay, or doing impulse-response measurement. The phase wraps to ±π by default; unwrapping can be useful for inspecting trends but is sensitive to noise.