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.
Sections
Mathematical Foundation
The continuous Fourier transform decomposes a time-domain signal x(t) into its frequency content:
For a digital signal sampled at discrete points x[n], we compute the Discrete Fourier Transform (DFT):
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:
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) |
| Sharp edges, hollow timbre |
Sawtooth |
| Bright, buzzy ramp |
Violin |
| Rich but smooth |
Clarinet |
| 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 |
FFT Analysis Parameters
The simulator runs at audio-CD sampling and uses an N = 1024 FFT:
Parameter | Value |
|---|---|
Sample rate | 44 100 Hz |
FFT size | 1024 bins |
Frequency resolution | ~43 Hz per bin |
Nyquist frequency | 22 050 Hz (max representable) |
Window length | ~23 ms (per analysis frame) |
FFT cost |
|
Δ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.
FFT Analysis Information
Usage
- 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.
- 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.
- Toggle
Show Oscillators: overlays each individual sine component (rainbow colors) on the time-domain trace, so you can literally watchx(t)being built up as the sum of its parts. - Pause / Run: freezes both panels for closer inspection of a single waveform frame.
- 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.
- 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.