Web Simulation 

 

 

 

 

Fast Fourier Transform (FFT) Tutorial 

This tutorial demonstrates the Fast Fourier Transform, the algorithm that connects the time domain (a waveform you can plot) to the frequency domain (the sine-wave ingredients that make up that waveform). The FFT is foundational to signal processing, audio analysis, communications, and almost every form of scientific computing that touches time series.

The simulator uses additive synthesis with up to 20 sine-wave oscillators, then runs the FFT on the composite signal in real time. The top panel shows the time-domain waveform (white) and its individual oscillator components (rainbow). The bottom panel shows the FFT spectrum, with yellow markers at each active oscillator's frequency so you can see synthesis and analysis side by side.

Mathematical Foundation

The continuous Fourier transform decomposes a time-domain signal x(t) into its frequency content:

X(f) = ∫ x(t) · e−j2πft dt

For a digital signal sampled at discrete points x[n], we compute the Discrete Fourier Transform (DFT):

X[k] = Σn=0N−1 x[n] · e−j2πkn/N

A naive evaluation of the DFT is O(N²). The Fast Fourier Transform algorithm reduces this to O(N log N) by exploiting symmetries in the complex exponentials — for N = 1024, that's a roughly 100× speedup, which is what makes real-time spectral analysis possible in this simulator.

Additive Synthesis

The signal generator builds its waveform by summing sine waves — the inverse of what the FFT does on the receive side:

x(t) = Σi=120 Ai · sin(2π fi t + φi)

Each oscillator i has its own amplitude Ai, frequency fi, and phase φi. The FFT then takes the composite x(t) and recovers exactly which frequencies were used and at what amplitudes — demonstrating that synthesis and analysis are inverse operations.

Waveform Recipes

Every periodic waveform has a unique "harmonic recipe" — the set of frequencies and amplitudes that sum to produce it. The preset dropdown loads these recipes into the oscillators:

Preset

Harmonic recipe

Character

Pure Sine

Fundamental only

Single tone

Rectangular (Square)

An = 1/n for odd n

Sharp edges, hollow timbre

Sawtooth

An = 1/n for all n

Bright, buzzy ramp

Violin

An = 1/n1.5 for all n

Rich but smooth

Clarinet

An = 1/n1.5 for odd n

Round, hollow

Organ (Octaves)

Only powers of 2: 1, 2, 4, 8, 16

Stable layered tone

5 Harmonics

First 5 harmonics, equal amplitude

Brassy

Two-Tone Beat

200 Hz + 220 Hz

Audible beating envelope

Church Bell

Inharmonic: 1, 2, 3, 4.2, 5.4, 6.8 × f0

Non-repeating, beating bell tone

Vocal "Ahh"

All harmonics with formant peak at n = 3–5

Speech-like vowel

Why Church Bell looks different: harmonic waveforms (square, sawtooth, violin…) have integer frequency ratios, so all components share a common period and the waveform repeats exactly. Inharmonic content (bell, drum) does not — the composite signal never repeats, which is why the spectrum bars are unevenly spaced and the time-domain trace keeps morphing.

FFT Analysis Parameters

The simulator runs at audio-CD sampling and uses an N = 1024 FFT:

Parameter

Value

Sample rate fs

44 100 Hz

FFT size N

1024 bins

Frequency resolution Δf = fs/N

~43 Hz per bin

Nyquist frequency fs/2

22 050 Hz (max representable)

Window length N/fs

~23 ms (per analysis frame)

FFT cost

O(N log2 N) = ~10 240 complex ops/frame

Frequency resolution limit: two tones closer in frequency than Δf ≈ 43 Hz fall into the same bin and appear as a single peak. To resolve them you need either a longer FFT (more bins) or a longer integration window — this is the time/frequency uncertainty principle in practical form. The Two-Tone Beat preset (200 Hz vs 220 Hz, separation 20 Hz) deliberately sits inside one bin so you see beating in time but a smeared peak in frequency.

Simulation

The interactive simulator is below. Pick a waveform preset to load a known harmonic recipe, then watch the time-domain waveform (top) and the FFT spectrum (bottom) update together. Toggle Show Oscillators to overlay the individual sine components on the time trace, or pause to study one frame. Fine-tune any of the 20 oscillators using the per-row frequency / amplitude / phase / enable controls.

Oscillator 1
200 Hz 30%
Oscillator 2
400 Hz 30%
Oscillator 3
600 Hz 30%
Oscillator 4
800 Hz 30%
Oscillator 5
1000 Hz 30%
Oscillator 6
1200 Hz 30%
Oscillator 7
1400 Hz 30%
Oscillator 8
1600 Hz 30%
Oscillator 9
1800 Hz 30%
Oscillator 10
2000 Hz 30%
Oscillator 11
2200 Hz 30%
Oscillator 12
2400 Hz 30%
Oscillator 13
2600 Hz 30%
Oscillator 14
2800 Hz 30%
Oscillator 15
3000 Hz 30%
Oscillator 16
3200 Hz 30%
Oscillator 17
3400 Hz 30%
Oscillator 18
3600 Hz 30%
Oscillator 19
3800 Hz 30%
Oscillator 20
4000 Hz 30%
0.001x

FFT Analysis Information

Sample Rate: 44,100 Hz
FFT Bins: 1024
Frequency Resolution: ~43 Hz per bin
Nyquist Frequency: 22,050 Hz

Usage

  1. Load a preset: Pick a waveform from the dropdown (Square, Sawtooth, Pure Sine, Violin, Organ, Clarinet, Church Bell, Vocal "Ahh", …). Each preset configures the 20 oscillators to the recipe for that waveform.
  2. Compare time and spectrum: The top panel shows the composite waveform; the bottom panel shows the FFT spectrum. Yellow vertical lines mark the exact oscillator frequencies, so you can verify the FFT correctly recovers what synthesis put in.
  3. Toggle Show Oscillators: overlays each individual sine component (rainbow colors) on the time-domain trace, so you can literally watch x(t) being built up as the sum of its parts.
  4. Pause / Run: freezes both panels for closer inspection of a single waveform frame.
  5. Tune the speed slider: 0.001x to 1.0x. Slower speeds make it easier to see how the components add up moment by moment; faster speeds reveal beating and longer-period behavior.
  6. Fine-tune individual oscillators: use the per-row frequency / amplitude / phase / enable controls to depart from the presets. Drop one harmonic of a square wave to see the spectrum bar disappear; double its amplitude to see the corresponding spectrum bar grow.

Parameters

Control

Range

Effect

Oscillator frequency

50–8000 Hz

Position of one sine component in the spectrum

Oscillator amplitude

−1.0 to +1.0

Height of the corresponding spectrum bar; sign flips phase by 180°

Oscillator phase

0°–360°

Time-shift of the component; affects waveform shape but NOT the magnitude spectrum

Oscillator enable

on/off

Include/exclude this oscillator from the sum

Waveform preset

10 presets

Loads the harmonic recipe for that waveform into the 20 oscillators

Show Oscillators

on/off

Overlay the individual component sine waves on the time-domain plot

Speed

0.001x–1.0x

Animation speed of the time-domain trace; slow values aid visual inspection

Pause/Run

toggle

Freeze or resume the animation

Key Concepts

  • Synthesis ↔ Analysis: additive synthesis builds a waveform by summing sines; FFT decomposes a waveform back into sines. They are inverse operations — what the simulator demonstrates is the round trip.
  • Harmonic recipe: the unique set of (frequency, amplitude, phase) triples that, when summed, reproduce a periodic waveform. Different "instruments" (square, sawtooth, violin, clarinet) differ exactly in their recipes — not in any time-domain "shape" rule.
  • Frequency resolution Δf = fs/N: two tones closer than ~43 Hz here cannot be resolved as separate peaks; they merge into one bin. Increasing N or lengthening the window improves resolution at the cost of slower update.
  • Nyquist frequency fs/2: the highest frequency that can be represented without aliasing. At 44.1 kHz sample rate, anything above 22 050 Hz folds back to a false lower frequency.
  • Phase does not show in the magnitude spectrum: changing an oscillator's phase shifts the waveform in time but leaves the spectrum bars at the same height. The FFT preserves phase in its complex output, but this simulator displays only the magnitude.
  • Inharmonic content (Church Bell): when frequency ratios are non-integer, no common period exists, the waveform never repeats, and the spectrum bars are unevenly spaced. This is what distinguishes pitched instruments from percussion in everyday hearing.

Limitations

This is an educational visualizer, not a production DSP tool. Notable simplifications:

  • The FFT is computed on a short window (~23 ms); spectral peaks are not as sharp as a long-integration analysis would give.
  • Only the magnitude spectrum is displayed. The phase response is computed internally but not shown.
  • No windowing is applied before the FFT, so spectral leakage from non-periodic-in-window content (drag a single oscillator's frequency continuously and watch the bar smear) is more pronounced than with a Hann or Hamming window.
  • The maximum oscillator frequency is capped at 8 kHz to keep the bars visible on the spectrum plot, well below the 22 kHz Nyquist limit.