Topics A–Z

Math

Fourier Series: Building Any Wave from Pure Sines

Stacking smooth sine waves can reproduce sharp square edges, sawtooth ramps, and complex audio. How orthogonality isolates each frequency, why energy splits cleanly, and why corners overshoot.

LVL 63 min read

For Readers comfortable with trigonometry, integrals, and basic waveforms.

LVL 5

A simpler explanation with fewer formulas.

A sine wave has no sharp corners and no abrupt jumps. Yet Joseph Fourier showed that virtually any periodic function — a digital clock pulse, a bowed violin string, a triangular ramp — can be written as a sum of pure sines and cosines whose frequencies are integer multiples of one base frequency.

A Fourier series decomposes a repeating waveform into its harmonic recipe: which frequencies are present, how loud each one is, and how they align in phase.

A Fourier series represents a T-periodic function as a superposition of harmonically related sinusoids — or complex exponentials — at integer multiples of the fundamental frequency ω₀ = 2π / T. What makes the decomposition powerful is not just existence, but geometry: the sinusoids form an orthogonal basis, so every harmonic coefficient can be extracted independently without solving a coupled system.

Fourier series synthesizer
EPICYCLESsumtarget (dashed)+10−1HARMONIC AMPLITUDES |bₙ|1357911131517192123252729
5Active terms
96.0%Energy captured
1.182Peak amplitude
1 / nDecay law

Each circle spins at an integer multiple of the base frequency. Switch to Fejér to taper the tail and remove Gibbs corner overshoot.

Drag the harmonic slider from 1 to 15 to watch rotating sine circles carve out square, sawtooth, and triangle waves — and toggle Fejér summation to see the Gibbs corner horns vanish.

The harmonic recipe

For a real function f(t) with period T and fundamental angular frequency ω₀ = 2π / T, the real trigonometric Fourier series is:

f(t)=a02+∑n=1∞[ancos⁡(nω0t)+bnsin⁡(nω0t)]f(t) = \frac{a_0}{2} + \sum_{n=1}^{\infty} \Big[ a_n \cos(n\omega_0 t) + b_n \sin(n\omega_0 t) \Big]

Here a₀ / 2 is the average (DC) value over one full cycle, while each pair (aₙ, bₙ) sets the amplitude and phase of the n-th harmonic.

Using Euler’s formula e^(iθ) = cos θ + i · sin θ collapses both cosine and sine terms into a single complex exponential series:

f(t)=∑n=−∞∞cn e inω0tf(t) = \sum_{n=-\infty}^{\infty} c_n\, e^{\,i n \omega_0 t}

For real-valued signals, c₀ = a₀ / 2, cₙ = (aₙ − i · bₙ) / 2 for n ≥ 1, and negative frequencies mirror positive ones by conjugate symmetry: c₋ₙ = cₙ*.

Orthogonality: how each frequency is isolated

How do you find how much of the 3rd harmonic hides inside a messy signal? Multiply your signal by a test wave running at 3× the base frequency, then average the product over one full cycle.

Any component oscillating at a different frequency spends equal time pulling the product positive and negative, so it cancels out to zero. Only the matching 3× component stays consistently in step and survives the average.

That cancellation is orthogonality. On [−π, π], for positive integers m and n:

∫−ππsin⁡(mx) sin⁡(nx) dx={0m≠nπm=n\int_{-\pi}^{\pi} \sin(mx)\,\sin(nx)\,dx = \begin{cases} 0 & m \neq n \\ \pi & m = n \end{cases}

The same holds for cos(m·x) · cos(n·x), while every sine–cosine product integrates to zero. Multiplying f(t) by a single basis wave and integrating over one period T knocks out every other harmonic at once:

an=2T∫0Tf(t)cos⁡(nω0t) dt,bn=2T∫0Tf(t)sin⁡(nω0t) dta_n = \frac{2}{T}\int_0^T f(t)\cos(n\omega_0 t)\,dt, \qquad b_n = \frac{2}{T}\int_0^T f(t)\sin(n\omega_0 t)\,dtcn=1T∫0Tf(t) e−inω0t dtc_n = \frac{1}{T}\int_0^T f(t)\, e^{-i n \omega_0 t}\,dt

Smoothness controls how fast harmonics fade

Three classic 2π-periodic waves of unit amplitude show how geometry dictates the spectrum:

WaveformFourier seriesCoefficient decayWhy
Square (±1)(4/π) · [ sin x + (1/3) sin 3x + (1/5) sin 5x + … ]1 / nSharp jump discontinuity
Sawtooth (x/π)(2/π) · [ sin x − (1/2) sin 2x + (1/3) sin 3x − … ]1 / nJump discontinuity, no half-wave symmetry
Triangle (±1)(8/π²) · [ sin x − (1/9) sin 3x + (1/25) sin 5x − … ]1 / n²Continuous, sharp slope corners

Notice the difference between the square wave and the triangle wave. The square wave has vertical cliffs, so it needs strong high-frequency harmonics all the way up (1/3, 1/5, 1/7…). The triangle wave never jumps — it only bends sharply at its peaks — so its harmonics drop off as 1/n² (1/9, 1/25, 1/49…), and just three terms already trace a convincing triangle.

Parseval’s identity guarantees that total mean-square energy is identical in the time domain and the frequency domain:

1T∫0T∣f(t)∣2 dt=(a02)2+12∑n=1∞(an2+bn2)=∑n=−∞∞∣cn∣2\frac{1}{T}\int_0^T |f(t)|^2\,dt = \left(\frac{a_0}{2}\right)^{2} + \frac{1}{2}\sum_{n=1}^{\infty}\left(a_n^2 + b_n^2\right) = \sum_{n=-\infty}^{\infty} |c_n|^2

For a ±1 square wave, |f(x)|² = 1 everywhere, so the total mean-square energy is 1. The fundamental alone contributes (1/2) · (4/π)² = 8 / π² ≈ 81.1% of the entire signal’s energy, while all remaining odd harmonics share the last 18.9%.

Integrating the coefficient formula by parts k + 1 times yields a direct smoothness law: if f is (k − 1) times continuously differentiable (C^(k−1)) and its k-th derivative has bounded variation with jumps, then |cₙ| = O(1 / |n|^(k+1)). Jump discontinuities (k = 0) decay as 1/n; continuous curves with corners (k = 1) decay as 1/n²; C¹ curves with curvature jumps decay as 1/n³; and smooth C^∞ periodic functions decay faster than any inverse power of n.

Corners never stop ringing: the Gibbs phenomenon

Add 5, 50, or 500 sine waves to build a ±1 square wave and something stubborn appears right next to every vertical jump: little horns sticking out past +1 and −1.

Adding more harmonics squeezes those horns closer and closer to the edge, making them thinner — but never shorter. On a ±1 square wave (jump height 2), the peak always overshoots to about ±1.18, roughly 9% of the jump height. This permanent corner ringing is the Gibbs phenomenon.

At any jump discontinuity of height J, the truncated Fourier sum S_N overshoots by a fixed fraction of the jump regardless of how large N grows:

1π∫0πsin⁡tt dt−12≈0.08949(≈8.95% of the jump)\frac{1}{\pi}\int_0^{\pi} \frac{\sin t}{t}\,dt - \frac{1}{2} \approx 0.08949 \quad (\approx 8.95\%\ \text{of the jump})

On a ±1 square wave (J = 2), the partial sum peaks near ±1.179. As N → ∞, the overshoot narrows to width O(1/N) and packs against the jump, so mean-square (L²) error still vanishes even though the maximum pointwise (L∞) error never drops below ~8.95% of J.

By Dirichlet’s theorem, any piecewise-smooth periodic function has a Fourier series that converges to f(x) at every point of continuity and to the midpoint (f(x⁺) + f(x⁻)) / 2 at every jump. Tapering harmonics with Fejér (Cesàro) weights 1 − |n|/M removes Gibbs overshoot altogether at the cost of a gentler edge — the root of windowing in digital signal processing.