Math Methods · interactive

Fourier Series Builder

Any periodic signal — even a hard-cornered square wave — is secretly a sum of pure sine waves. Add the harmonics one at a time and watch the shape assemble itself. Then flip to the phasor view and see the same series as a chain of spinning circles drawing the wave.

f(x) = a₀/2 + Σ [ aₙ cos nx + bₙ sin nx ]
Each coefficient aₙ, bₙ is how much of that harmonic the signal contains — found by integrating f against cos nx and sin nx over one period.

Target signal vs. partial sum

target signal Fourier partial sum individual harmonics

Frequency spectrum · coefficient magnitude per harmonic

Harmonics
8
RMS error
Gibbs overshoot

Target waveform

Number of harmonics

8

Why this works

The sines and cosines of different whole-number frequencies are orthogonal — multiply any two different ones, integrate over a period, and you get zero. That's the whole trick. It means each harmonic's coefficient can be read off independently by projecting the signal onto it: bₙ = (1/π)∫ f(x) sin(nx) dx. No harmonic interferes with the measurement of another. (This builder computes those integrals numerically, so you can drop in any waveform.)

The Gibbs phenomenon

Pick the square wave and push the harmonic count up. The fit gets better everywhere — except right at the jumps, where a stubborn overshoot refuses to shrink. Add a thousand terms and it's still about 9% (≈8.95%) too tall; the spike just gets narrower, never shorter. This is the Gibbs phenomenon, and it's why sharp edges are hard for any finite series. Now switch to the triangle: it's continuous, so there's no overshoot and the series converges far faster — watch the spectrum fall off like 1/n² instead of 1/n.

Harmonics as spinning circles

Hit Phasor view. Each term aₙcos + bₙsin is one rotating vector spinning at frequency n; stack them tip-to-tail and the end of the chain traces out f(x) as it scrolls by. A square wave is a handful of circles; the more you add, the crisper the corners. This is the same idea behind those "draw anything with epicycles" animations — and behind how an FM radio, an MRI, and a JPEG all think about the world.

EngineeringCandy · coefficients integrated numerically, series & phasors rendered live · build it, break it, learn