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) dxbₙ = (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.
〰️ Fourier Series Decomposition
About this simulation
This simulation builds periodic waveforms by summing pure sine and
cosine harmonics, the central idea of Fourier analysis. The same
decomposition underpins audio compression (MP3), JPEG images, MRI
scanners and digital signal processing everywhere. It is striking that
sharp-cornered shapes like square and sawtooth waves emerge from
nothing but smooth, rotating circles.
How it works
Pick a target waveform (square, sawtooth, triangle, pulse or half-wave).
Each harmonic is drawn as a rotating arm (epicycle) whose radius is its Fourier amplitude.
The arms are stacked tip-to-tip and the final tip traces the reconstructed wave.
Add more terms (N) to watch the approximation sharpen toward the ideal shape.
Key equations
f(x) = a0/2 + Σ [an·cos(nx) + bn·sin(nx)] — f(x) is the
target wave, n is the harmonic number, and an, bn are the Fourier
coefficients found by projecting f onto each sinusoid.
Controls
Waveform buttons — choose square, sawtooth, triangle, pulse or half-wave.
N harmonics — number of terms (1–50) used in the partial sum.
Speed — animation rate of the rotating epicycles (0.1×–3×).
Stats bar — live term count, max error, energy captured and leading harmonic.
Did you know?
Near a jump discontinuity the partial sum always overshoots by about
8.9% no matter how many terms you add — the Gibbs phenomenon — which is
why digital audio can ring near sharp transients.
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.