Fourier Series Synthesiser

Animated phasor chains build classic waveforms harmonic by harmonic — adjust N and watch the Gibbs phenomenon

Preset: Square Wave Frame: 0 N harmonics active
f(x) = (4/π)·[sin x + sin 3x/3 + sin 5x/5 + ...]

Fourier Series: Any Periodic Function as Sines and Cosines

In 1822, Joseph Fourier proved that virtually any periodic function can be reconstructed as an infinite sum of sines and cosines. This is one of the most powerful and far-reaching results in all of mathematics, with applications in signal processing, quantum mechanics, heat conduction, image compression (JPEG), audio (MP3), and hundreds of other fields.

Fourier series definition: For a function f(x) with period 2π, f(x) = a₀/2 + Σ(n=1..∞) [aₙ cos(nx) + bₙ sin(nx)]
where the Fourier coefficients are:
aₙ = (1/π) ∫₋π^π f(x) cos(nx) dx    bₙ = (1/π) ∫₋π^π f(x) sin(nx) dx

Analytic Formulae for the Six Presets

WaveformFourier SeriesCoeff decay
Square(4/π)·[sin x + sin 3x/3 + sin 5x/5 + …] (odd harmonics only)O(1/n)
Sawtooth(2/π)·[sin x − sin 2x/2 + sin 3x/3 − …] (all harmonics, alternating sign)O(1/n)
Triangle(8/π²)·[sin x − sin 3x/9 + sin 5x/25 − …] (odd n, alternating)O(1/n²)
Half-Wave Rect1/π + sin x/2 + (2/π)·[cos 2x/3 − cos 4x/15 + …]O(1/n²)
Pulse (d=25%)0.25 + Σ (2sin(nπd)/nπ)·cos(nx), d=¼O(1/n)
CustomNumeric DFT of drawn curve (512 samples)Depends on smoothness

Notice the coefficient decay rates. For smooth functions (like the triangle wave, which is C⁰ but not C¹), coefficients decay at least as fast as O(1/n²). For discontinuous functions (square, sawtooth), they decay only as O(1/n). This slow decay is directly responsible for the Gibbs phenomenon — the partial sums need many terms to "resolve" the sharp jump.

The Gibbs Phenomenon

Set the preset to Square wave and increase N from 1 to 50. The partial sum approximation becomes sharper and sharper near the discontinuity — but the overshoot peak never disappears. No matter how large N becomes, the maximum overshoot remains approximately 8.9% of the jump height.

Gibbs constant: lim_{N→∞} max overshoot / jump height = (2/π) ∫₀^π sinc(x) dx − 1 = (Si(π)/π) − ½ ≈ 0.0894898... i.e. about 8.95% where Si(x) = ∫₀^x sin(t)/t dt (sine integral)

The overshoot does shrink in width — it concentrates into an ever-thinner spike near the discontinuity — but its height converges to the Gibbs constant, not zero. This matters for signal processing: Gibbs ringing in bandlimited reconstructions causes artefacts, motivating window functions (Hann, Hamming) and Fejér summation methods.

Phasor Representation

Every sinusoidal term aₙcos(nx) + bₙsin(nx) can be written as a single rotating vector (phasor) of radius Aₙ =√(aₙ²+bₙ²) rotating at angular speed n. Chaining these phasors tip-to-tail — as shown on the left panel — is exactly the animation in the simulator. The y-coordinate of the final phasor tip traces the Fourier partial sum over time.

Complex Fourier form: f(x) = Σ_{n=−∞}^{+∞} cₙ · e^{inx} where cₙ = (aₙ − i·bₙ)/2 for n>0, c₀ = a₀/2, c₋ₙ = (aₙ + i·bₙ)/2 |cₙ| = √(aₙ²+bₙ²)/2 = amplitude of nth phasor arg(cₙ) = initial phase of nth phasor

Convergence Theory

Applications

Frequently Asked Questions

Why do square and sawtooth waves have only O(1/n) decay?
Integration by parts gives the rule: if f has a jump discontinuity, its Fourier coefficients decay as 1/n (from the boundary terms in the integration). Each additional degree of smoothness adds one power of 1/n to the decay rate. The square wave has 0 continuous derivatives (it's discontinuous), so 1/n. The triangle wave is continuous but has a discontinuous derivative, so 1/n². The parabola is C¹ with discontinuous second derivative, so 1/n³. A C∞ function (e.g. sin x itself) has superpolynomial decay. A C∞ periodic analytic function has exponential decay |cₙ| ≤ C·r^n for some r<1.
What is the difference between Fourier series and the Fourier transform?
The Fourier series represents a periodic function as a discrete sum of harmonics (integer frequencies only). The Fourier transform f̂(ξ) = ∫f(x)e^{−2πiξx}dx decomposes an aperiodic function (defined on all of ℝ) into a continuous spectrum of frequencies. The Fourier series is the discrete special case: you can derive it by taking the Fourier transform of a periodised version of f, which produces a Dirac comb of delta functions at integer frequencies. Conversely, the Fourier series coefficients of a periodic function are samples of the Fourier transform spaced at intervals of 1/(period).
Why can the same phasor idea draw arbitrary shapes (like letters)?
A closed curve parametrised as z(t) = x(t) + iy(t) for t ∈ [0,2π] can also be expanded in a Fourier series: z(t) = Σ cₙ e^{int}. Each cₙ e^{int} is a circle of radius |cₙ| rotating at frequency n (positive frequencies rotate counterclockwise, negative frequencies clockwise). Chaining them produces the epicycle animations seen in 3Blue1Brown-style videos. The only difference from waveform synthesis is that both the x and y components are synthesised simultaneously via complex Fourier coefficients, so any 2D closed curve — including letters, portraits, and drawings — can be traced.

Part of MySimulator.uk — 55+ interactive simulations · Read: Measure Theory · All Simulations