Fourier series
Draw a waveform or choose a preset, then adjust the number of harmonics to compare the reconstruction with the original signal.
f(t) = a₀/2 + Σ [aₙ cos(nωt) + bₙ sin(nωt)]
What to try
What you'll learn
- Any repeating wave is a sum of sine waves
- What the coefficients aₙ, bₙ and the spectrum tell you
- How rotating circles (epicycles) draw a signal
- Why sharp jumps need many harmonics (Gibbs phenomenon)
Try this
- Pick Square, set Harmonics to 1, press Play, then raise it slowly. Watch the corners sharpen.
- Compare the spectra of Square and Triangle. Which one dies off faster?
- Draw your own shape and find the fewest harmonics that still look right.
Understanding Fourier series
A Fourier series says any repeating function can be rebuilt from sine and cosine waves, however jagged it looks. Each of those waves is called a harmonic. The first one (n = 1) does one cycle per period, the second does two, and so on. Add them in the right amounts and you get the original wave back.
The Fourier series formula
For a periodic function f(t) with fundamental angular frequency ω, the Fourier series is:
The coefficients aₙ and bₙ measure how much of each harmonic is present. This simulation computes them directly from the N sampled points of your drawn or preset waveform:
a₀/2 is the average ("DC") value of the signal, aₙ is the amount of the n-th cosine harmonic, and bₙ is the amount of the n-th sine harmonic. Combining them gives the amplitude and phase of harmonic n:
Cₙ is the length of that harmonic's phasor arm in the animation above, and φₙ is its starting angle, chosen so that Cₙ·sin(nt + φₙ) reproduces aₙ·cos(nt) + bₙ·sin(nt) exactly. The frequency spectrum panel plots Cₙ for every harmonic: tall bars mean that frequency contributes strongly to the shape of the wave.
Epicycles: phasors that draw the wave
The animation panel visualizes the series as a chain of rotating vectors (phasors), sometimes called epicycles. The first phasor spins once per period with length C₁; the tip of that phasor is the pivot for the second phasor, which spins twice as fast with length C₂; and so on through however many harmonics the slider selects. The final tip position, traced out over time, is exactly a₀/2 + Σ[aₙcos(nt) + bₙsin(nt)], the partial Fourier sum. As you drag the harmonics slider higher, more (smaller, faster-spinning) arms are added to the chain and the traced signal on the right converges toward the original drawn or preset waveform.
Why different shapes decompose differently
How fast the harmonic amplitudes shrink depends on the shape being decomposed:
- Sine: a single harmonic (n = 1) carries the entire signal; nothing else is needed.
- Square wave: only odd harmonics (1, 3, 5, …) appear, with amplitude falling off as 1/n. Because the amplitude decays slowly, a square wave needs many harmonics to approximate well.
- Sawtooth wave: every harmonic (odd and even) appears, also decaying as 1/n.
- Triangle wave: only odd harmonics appear, but they decay much faster, as 1/n², so a triangle wave is well approximated with far fewer harmonics than a square or sawtooth wave.
The Gibbs phenomenon
Try the square wave preset and watch the reconstructed trace near its sharp jumps as you increase the harmonics slider. A small overshoot appears right at each discontinuity, and it does not shrink away as more harmonics are added; it just squeezes into a narrower spike sitting at roughly the same height, about 9% of the jump size. This persistent ringing near a discontinuity is called the Gibbs phenomenon, and it's an unavoidable feature of representing a sudden jump with a finite sum of smooth sine and cosine waves. The sawtooth wave has the same kind of jump, from +1 back down to -1 as it repeats, so it shows the same overshoot. The triangle wave, by contrast, has corners but no jumps (it wraps back to its starting value continuously), so it reconstructs without any Gibbs overshoot.
