🎵

Fourier Series

Any periodic function = sum of sinusoidal harmonics. Watch epicycles compose waves in real time.

Mathematics Signal Processing Harmonics Gibbs Phenomenon
Waveform:
Terms: 1 Max error: Energy captured: Leading harmonic: f₁

🎵 Fourier Series

Jean-Baptiste Joseph Fourier showed (1822) that any periodic function f(x) can be written as an infinite sum of sines and cosines:

f(x) = a₀/2 + Σₙ₌₁ [aₙ cos(nx) + bₙ sin(nx)]

Coefficients are computed by projection: aₙ = (1/π) ∫ f(x) cos(nx) dx   bₙ = (1/π) ∫ f(x) sin(nx) dx

Gibbs phenomenon: near jump discontinuities (square/sawtooth waves) the partial sum overshoots by approximately 8.9% no matter how many terms are added — a fundamental property of Fourier approximation near discontinuities.

Parseval's theorem: the total energy in a signal equals the sum of energies in each harmonic: (1/π) ∫ |f|² dx = a₀²/2 + Σ (aₙ² + bₙ²)

The epicycle diagram (left) shows each harmonic as a rotating arm — the tip traces the function value, just as Ptolemy's epicycles approximated planetary paths.

About Fourier Series

The Fourier series is a mathematical technique for representing any periodic function as an infinite sum of sine and cosine waves of integer multiples of a fundamental frequency. Joseph Fourier showed in 1822 that even discontinuous periodic functions—like a square wave or sawtooth—can be approximated to arbitrary accuracy by adding up harmonics. The series is: f(x) = a₀/2 + Σ[aₙcos(nω₀x) + bₙsin(nω₀x)], where the coefficients aₙ and bₙ are computed from integrals of the original function.

Adding more harmonics progressively refines the approximation. With only the fundamental frequency you get a smooth sine wave; adding the third, fifth, seventh harmonics (for a square wave) builds the characteristic sharp corners and flat tops. Near a discontinuity, the partial sum always overshoots by about 9%—a phenomenon called the Gibbs phenomenon that persists regardless of how many terms are added. Fourier analysis is the mathematical foundation of signal processing, audio compression, image analysis, and quantum mechanics.

This simulator lets you choose a target waveform (square, sawtooth, triangle, or custom), add harmonics one by one, and watch the partial sum converge toward the original function. The spinning phasors (epicycles) representation—where each harmonic is a rotating arrow—makes it viscerally clear how sinusoidal building blocks combine to create complex shapes, illustrating a key insight of mathematical analysis.

Frequently Asked Questions

Why can any periodic function be represented as a sum of sines and cosines?

Sines and cosines of different frequencies form an orthogonal basis for the space of periodic functions—analogous to how x, y, z unit vectors form a basis for 3D space. Just as any 3D vector can be decomposed into x, y, z components, any periodic function can be decomposed into sine and cosine components at each frequency. The orthogonality property means each coefficient can be computed independently by multiplying by the corresponding sine or cosine and integrating over one period.

What is the Gibbs phenomenon?

The Gibbs phenomenon is the ~9% overshoot that occurs near a jump discontinuity in a function when approximated by a finite Fourier series. As you add more terms, the overshoot gets sharper and narrower but never disappears—it converges to a spike of constant height (~9% of the jump) at the discontinuity. This is not an error in Fourier theory but a genuine mathematical property: pointwise convergence of the partial sums fails at discontinuities even as the mean-squared error goes to zero.

How is Fourier series related to Fourier transform?

The Fourier series applies to periodic functions and decomposes them into discrete harmonics at frequencies nω₀. The Fourier transform generalizes this to non-periodic functions, replacing the discrete sum with a continuous integral over all frequencies: F(ω) = ∫f(t)e^(-iωt)dt. The Fourier series can be seen as the special case where the period T → ∞ and the discrete spectrum becomes continuous. Both share the same mathematical structure: representing a function in frequency space.

What are even and odd functions and how do they simplify Fourier series?

An even function satisfies f(-x) = f(x) and has only cosine terms (bₙ = 0) in its Fourier series. An odd function satisfies f(-x) = -f(x) and has only sine terms (aₙ = 0). A square wave centered at the origin is odd (only odd sine harmonics), while a triangular wave is also odd. Recognizing symmetry halves the computation. A general function can always be split into even and odd parts: f(x) = [f(x)+f(-x)]/2 + [f(x)-f(-x)]/2.

How is Fourier series used in music and audio?

Every musical instrument produces a characteristic harmonic spectrum—the mix of fundamental and overtone frequencies that defines its timbre. A violin and a flute playing the same note have identical fundamental frequency but different harmonic content (Fourier coefficients). Audio compression algorithms like MP3 use psychoacoustic models combined with Fourier analysis to identify and discard frequency components the human ear cannot detect, achieving 10:1 compression ratios. Equalizers adjust the amplitude of different frequency bands (Fourier coefficients) to shape the overall sound.

What does the N harmonics slider do, and why does the waveform look better with more terms?

N harmonics (1 to 50) sets how many terms of the Fourier series are summed to approximate the target waveform. With N = 1 you see only the fundamental sine wave; each additional term adds a higher-frequency harmonic that refines sharp corners and flat regions. The "Max error" and "Energy captured" stats update live as you drag the slider, showing that error shrinks and captured energy approaches 100% as N grows — except right at any jump discontinuity, where the Gibbs overshoot persists no matter how large N gets.

Why do square and sawtooth waves need so many more harmonics than a triangle wave to look clean?

The Fourier coefficients of a waveform fall off more slowly the sharper its discontinuities are. A square wave has a jump discontinuity in the function itself, so its coefficients decay as 1/n and it needs many terms (and always shows Gibbs overshoot). A triangle wave has no jump — only a kink in its slope — so its coefficients decay faster as 1/n², meaning far fewer harmonics are needed before the reconstruction looks visually smooth.

What does the epicycle diagram on the left actually represent?

Each harmonic in the Fourier series is drawn as a rotating arm (phasor) whose length equals that harmonic's amplitude and whose rotation rate equals its frequency multiple n. The arms are chained tip-to-tail, exactly the way Ptolemy's ancient epicycles combined circular motions to approximate planetary paths; the tip of the final arm traces out the same waveform shown on the right, making visible how summing rotating vectors builds up a complex periodic shape from simple circular motions.

What does the Speed slider change, and does it affect the accuracy of the approximation?

Speed (0.1× to 3×) only scales how fast the epicycle arms rotate and the waveform animates across the canvas in real time — it has no effect on the underlying mathematics. The Fourier coefficients, the Max error, and the Energy captured stat are all fixed once you choose a waveform and N harmonics; Speed is purely a visualization control for slowing down or speeding up the animation to study the phasor motion more closely.

What is the "Leading harmonic" stat, and why does it stay at f₁ for some waveforms even at high N?

The Leading harmonic stat reports which term contributes the largest Fourier coefficient — usually the fundamental f₁, since coefficients generally decrease with harmonic number for the square, sawtooth, triangle, pulse and half-wave presets offered here. It stays fixed at f₁ across most N values because adding higher harmonics refines fine detail near discontinuities but rarely overtakes the fundamental's dominant contribution to the overall waveform shape.