FFT Magnitude Spectrum

The discrete Fourier transform (DFT) reveals how much of each sinusoidal frequency is present in a finite sequence of samples. This simulator fixes N = 256 real-valued samples x[n], computes a radix-2 fast Fourier transform (FFT) in software, and plots the magnitudes |X[k]| for frequency bins k = 0 through N/2, covering the DC component, positive-frequency bins, and the Nyquist bin. The time-domain view shows the sample sequence as a polyline; users can load presets (pure sine with an integer number of cycles in the window, two-tone mixture, band-limited square wave, centered impulse, or uniform noise) or paint the waveform directly, which switches to a custom buffer. Peak normalization in the spectrum panel emphasizes relative energy distribution. The companion Fourier Series page builds periodic waveforms by adding harmonics in the time domain; this page performs the complementary frequency-domain analysis on a fixed-length window, foreshadowing the continuous Fourier transform, windowing effects, and spectral leakage when a non-integer number of cycles is captured.

Who it's for: Undergraduate students in signals and systems, numerical analysis, or physics labs introducing spectral analysis, and anyone who already saw Fourier series and wants the discrete transform picture.

Key terms

  • Discrete Fourier Transform (DFT)
  • Fast Fourier Transform (FFT)
  • Frequency bin
  • DC component
  • Nyquist frequency
  • Magnitude spectrum
  • Time–frequency intuition
  • Spectral leakage

How it works

Sample a real signal on N = 256 points, then take a radix-2 FFT. The lower panel shows magnitude |X[k]| for bins k = 0 … N/2 (DC, positive frequencies, Nyquist). A single sine with an integer number of cycles in the window gives a narrow peak; a pulse spreads energy across bins—time–bandwidth intuition before the continuous Fourier transform.

Key equations

X[k] = Σ_{n=0}^{N−1} x[n] · e^{−2π i kn/N}
|X[k]| = √(Re² + Im²) · k = 0 … N/2

Frequently asked questions

Why does the sine preset give a tall bar at one bin?
When the sine completes an integer number of full cycles across exactly N samples, its energy aligns with a single DFT basis vector (up to the conjugate symmetry mirror at N−k). That produces a concentrated peak. If you painted a sine-like wave with a non-integer number of cycles, energy would spread across neighboring bins—an example of leakage tied to implicit rectangular windowing.
Why is the impulse preset’s spectrum spread out instead of a single spike?
A single nonzero sample is the discrete analogue of a very short pulse. In the frequency domain, short time localization forces a broad spectral footprint. Conversely, a narrowband tone in frequency requires many oscillations across the window—illustrating the reciprocal relationship between duration and bandwidth.
Are the green bars power, amplitude, or something else?
They show the magnitude |X[k]| = √(Re(X[k])² + Im(X[k])²) of each complex coefficient. The display scales bars by the largest magnitude so peaks are easy to compare; absolute numbers appear in the sidebar for DC, the strongest interior bin, and Nyquist.
Does this replace a full FFT library for real engineering work?
No. It is a teaching FFT with a fixed length, no window functions beyond the implicit rectangle, no zero-padding controls, and no phase plot. Production spectrum analyzers add windowing, overlap, calibration, and often use hardware-accelerated transforms.