Fourier Series & the Fourier Transform
Every musical note, every vowel sound, every clang of a bell is a pressure wave that repeats over and over. Joseph Fourier's astonishing 1807 claim was that any such repeating wave — no matter how jagged — can be rebuilt exactly from an infinite sum of pure sine waves. This is the idea that powers synthesizers, MP3 compression, and the equalizer in your headphones app.
Periodic signals as sums of sines
A sound wave is periodic with period T if it repeats itself exactly every T seconds: p(t) = p(t + T). A pure tone — a single sine wave — is the simplest periodic signal. But a violin note, a human vowel, or a square-wave synth patch all look far messier than a sine on an oscilloscope, and yet they still repeat with a fixed period.
Fourier's theorem says that any reasonably well-behaved periodic function can be written as a sum of a constant (the average, or DC offset) plus sine and cosine waves at integer multiples of the fundamental frequency f₀ = 1/T — these multiples are called harmonics.
The numbers a₀, a₁, a₂, … and b₁, b₂, … are the Fourier coefficients. They tell you exactly how much of each harmonic is present — this list of numbers is the timbre of the sound. A flute has energy concentrated in the first few harmonics; a brighter, buzzier oboe has energy spread across many more.
The Fourier series coefficients
The coefficients are found by projecting the signal onto each harmonic — multiplying by a sine or cosine of that frequency and integrating over one period. This works because sines and cosines of different harmonic numbers are orthogonal: their product integrates to zero over a full period unless the frequencies match.
aₙ = (2/T) ∫₀T p(t)·cos(2π n f₀ t) dt
bₙ = (2/T) ∫₀T p(t)·sin(2π n f₀ t) dt
Once you have aₙ and bₙ, it's often more useful to combine them into a single magnitude and phase per harmonic — this is exactly what a spectrum analyser displays as bars rising above each frequency:
φₙ = atan2(bₙ, aₙ) (phase of harmonic n)
Worked example: the square wave
A classic synth square wave (amplitude ±1, period T) contains only odd harmonics, falling off as 1/n:
= (4/π) [ sin(ωt) + sin(3ωt)/3 + sin(5ωt)/5 + sin(7ωt)/7 + … ]
This is why a square wave sounds hollow and "clarinet-like" compared to a sawtooth (which has both even and odd harmonics, falling off as 1/n, and sounds brighter and buzzier). You can hear the difference directly: play just the fundamental, then add the 3rd harmonic at 1/3 amplitude, then the 5th at 1/5, and the tone edges from a soft sine toward a harsh square.
The Gibbs phenomenon
A perfect square wave has an instantaneous, infinitely sharp jump — but every partial sum of finitely many sine waves is smooth. As you add more harmonics, the approximation gets closer to the square wave almost everywhere, but right at the jump a stubborn overshoot of about 9% of the jump height refuses to shrink, no matter how many harmonics you add. This is the Gibbs phenomenon, discovered by Josiah Willard Gibbs in 1899.
Complex exponential form
Engineers almost always write the Fourier series using complex exponentials instead of separate sines and cosines — via Euler's formula eiθ = cos θ + i sin θ, the whole sum collapses into one elegant expression:
cₙ = (1/T) ∫₀T p(t) · e−i 2π n f₀ t dt
Here cₙ is a single complex number per harmonic that packages both amplitude (|cₙ|) and phase (arg cₙ) together, and negative n simply represents the "negative frequency" partner needed to keep p(t) real-valued. This is the form used almost universally in signal processing — including the FFT, which computes a finite, sampled version of exactly this sum.
From series to transform
The Fourier series only applies to periodic signals. But most interesting sounds — a spoken sentence, a drum hit, a burst of noise — are not periodic at all. The Fourier transform generalises the idea by treating a non-periodic signal as the limit of a periodic one whose period T tends to infinity. As T → ∞, the spacing between harmonics (1/T) shrinks to zero, the discrete sum over n becomes a continuous integral over frequency f, and the coefficients cₙ become a continuous function X(f):
x(t) = ∫−∞∞ X(f) · ei 2π f t df (inverse transform)
X(f) is called the spectrum of x(t): a continuous density of frequency content rather than a discrete list of harmonic amplitudes. Every frequency, not just integer multiples of f₀, can now carry energy.
The discrete version: DFT
Computers can't integrate over infinite continuous time, so digital audio uses the Discrete Fourier Transform (DFT), applied to N samples of a signal:
Computed directly, this costs O(N²) multiplications. The
Fast Fourier Transform (FFT) — Cooley & Tukey,
1965 — recursively splits the sum into even- and odd-indexed samples,
reducing the cost to O(N log N). This is what makes real-time
spectrum analysers, pitch detectors, and audio equalizers possible on
ordinary hardware; the Web Audio API's
AnalyserNode runs exactly this algorithm every animation
frame.
Try it yourself
Watch harmonics being added one at a time, rotating as phasors around a circle, tracing out the waveform in real time — including the square wave overshoot from the Gibbs phenomenon:
Or explore live additive synthesis, adjusting each harmonic's amplitude yourself: