Fourier Series Builder

compose complex waves from simple sines

Loading interactive simulation...

Lesson

The theory — Fourier Series Builder

A Fourier series is the claim that any periodic wave, however jagged, is a sum of pure sines whose frequencies are whole-number multiples of one fundamental. The sum is built one term at a time and drawn over the target. The interesting word is equals: the sum reaches the target everywhere the target is continuous, and the Peak row is where you find out what happens where it is not.

What each symbol means

N
how many terms are being added. The slider stops at 20, and the series row names every coefficient it is using.
k
the harmonic index — which multiple of the fundamental a term carries. The square and triangle use odd k only; the sawtooth uses every k.
aₖ
the coefficient of harmonic k, printed in the series row. Its size says how much that frequency matters, and how fast the coefficients shrink decides how fast the sum converges.
Peak
max|fN(x)|, the tallest point of the partial sum. The target has amplitude 1, so this row is really asking: has the sum overshot?

Where the formula comes from

  1. Read the coefficients off the page. For the square wave the series row prints 1.273 sin(x) + 0.4244 sin(3x) + 0.2546 sin(5x) + …, which is 4/(kπ) at k = 1, 3, 5. Nothing is fitted — the coefficients come from an integral, and every waveform has its own.
  2. Notice which harmonics are missing. Square and triangle use odd k only, because both satisfy f(x + π) = −f(x): shift them half a period and they flip, and an even harmonic cannot do that. The sawtooth has no such symmetry, so it needs every harmonic — which the "Harmonics used" row states outright.
  3. The first coefficient already tells you the convergence speed. Square gives 4/π = 1.273 and decays like 1/k; triangle gives 8/π² = 0.8106 and decays like 1/k²; sawtooth gives 2/π = 0.6366 and decays like 1/k. Faster decay means fewer terms for the same fidelity — which is why the triangle looks finished long before the other two.
  4. Now watch the Peak row instead of the picture. For a target with no jumps the peak should climb to 1 and stop. For a target with a jump, it does something else entirely, and that is the rest of this lesson.

How to read what you see

Set the shape to triangle and walk N from 1 upward: the peak reads 0.8106, 0.9006, 0.9331, 0.9596 … 0.9899 at N = 20. It climbs towards 1 from below and never passes it. Now switch to square: 1.273, 1.2, 1.188, 1.182 … and then it simply stops, at 1.179, and no further harmonic moves it. Finally the sawtooth: 0.6366, 0.827, 0.9185, then 1.008 at N = 5 — it crosses 1 — and by N = 20 it is at 1.131 and still climbing. Three shapes and three completely different stories in one row. The sawtooth is the one that misleads: watch it alone and you would conclude the overshoot grows without limit. It does not. It is heading for the same 1.179 as the square, just approaching from underneath.

Assumes
That twenty terms is enough to see the trend, and that the peak is found by sampling — the RMS row is evaluated at 801 points across the period, and the peak is the largest of those samples rather than a solved maximum. Both are fine for watching convergence and neither would do for a proof.
Breaks when
The overshoot never goes away. That flat 1.179 is not the series running out of patience: the limit is (2/π)·Si(π) = 1.17898…, and adding harmonics for ever makes the spike narrower without making it shorter. So the series converges to the square wave at every individual point and never converges uniformly, which is the distinction the whole phenomenon exists to teach. It also explains an apparent contradiction on this page: the insight above says the overshoot is about 8.95% and this row says 17.9%. Both are correct — 0.179 measured against the amplitude of 1 is 0.0895 measured against the jump of 2. Michelson met the spike in 1898 on his own harmonic analyser and suspected a fault in the machine; Gibbs wrote to Nature the following year to explain that the mathematics was doing it, not the brass.

how rotating vectors build a waveform 🖖

Each rotating vector contributes one sine component at harmonic index k. Adding vectors tip-to-tail forms the partial sum fN(x). As N grows, high-frequency content sharpens corners, while near jump discontinuities a bounded Gibbs overshoot remains.

Every repeating wave is a chord of sines 🖖

Every term here is a sine at a whole-number multiple of one fundamental frequency, and switching between the three shapes changes the law those terms follow, not just their size. A square wave's harmonics fall off as 1/k: the 3rd carries a third of the fundamental's amplitude, the 5th a fifth. A triangle's fall as 1/k², so its 5th is already down to a twenty-fifth and eight terms draw a triangle you cannot fault by eye. What sets the exponent is the worst thing the wave does: the square jumps, the triangle only turns a corner. A jump buys 1/k, a corner buys 1/k², and that one exponent decides both how many terms you need and whether the overshoot at the edges shows up at all — it does for square and sawtooth, never for triangle.

The 9% overshoot that never goes away 🖖

Near a jump, the partial sum overshoots by about 8.95% of the jump height — and this spike never shrinks, no matter how many harmonics you add; it only grows narrower. Physicist Albert Michelson met it in 1898 when his mechanical harmonic analyzer kept drawing stubborn spikes at a square wave's edges, and he suspected a machine fault. J. Willard Gibbs proved the hardware was right: the overshoot is real mathematics. The same 'ringing' haunts JPEG images near sharp edges.

FOURIER THEORY — WHY SOME WAVES NEED MORE HARMONICS

Reading a Waveform: How Fast Will Its Harmonics Decay?

Every periodic wave is a sum of sines. How many you need before the sum looks right is not a matter of taste — it is fixed by how smooth the target waveform is. A jump costs far more harmonics than a corner, symmetry can halve the work for free, and one particular error never goes away no matter how many terms you add.

Square — a jump, so 1/n decay cn ∝ 1/n, n = 2k+1
Sawtooth — a jump with no symmetry, so every harmonic cn ∝ 1/n, ∀n
Triangle — a corner, not a jump, so 1/n² decay cn ∝ 1/n2, n = 2k+1
One harmonic — the price of stopping early ε ≈ ∑n>N cn

01

Square — a jump, so 1/n decay

Waveform has: A vertical jump between two levels, plus half-wave symmetry.

Coefficient decay: cn ∝ 1/n, n = 2k+1

What you see: 10 harmonics give sharp edges that still overshoot the jump by about 9% of its height.

Open this case: square, 10 harmonics
Square — a jump, so 1/n decay. Ten harmonics: the edges are sharp, but the overshoot is still there. A vertical jump between two levels, plus half-wave symmetry.
Ten harmonics: the edges are sharp, but the overshoot is still there.

02

Sawtooth — a jump with no symmetry, so every harmonic

Waveform has: One jump per period, and no half-wave symmetry to cancel anything.

Coefficient decay: cn ∝ 1/n, ∀n

What you see: 10 harmonics: ringing at each jump, and every harmonic 1, 2, 3… pulls its weight.

Open this case: sawtooth, 10 harmonics
Sawtooth — a jump with no symmetry, so every harmonic. Every harmonic contributes, and the ringing sits at each jump. One jump per period, and no half-wave symmetry to cancel anything.
Every harmonic contributes, and the ringing sits at each jump.

03

Triangle — a corner, not a jump, so 1/n² decay

Waveform has: The wave itself is continuous; only its slope jumps.

Coefficient decay: cn ∝ 1/n2, n = 2k+1

What you see: 8 harmonics already sit almost exactly on the target, with no overshoot at all.

Open this case: triangle, 8 harmonics
Triangle — a corner, not a jump, so 1/n² decay. Eight harmonics track the triangle almost exactly, with no ringing. The wave itself is continuous; only its slope jumps.
Eight harmonics track the triangle almost exactly, with no ringing.

04

One harmonic — the price of stopping early

Waveform has: You cut the sum off at a small N. The question is what got left behind.

Coefficient decay: ε ≈ ∑n>N cn

What you see: A square wave at n = 1 is a single sine: the right period, none of the shape.

Open this case: square, 1 harmonic
One harmonic — the price of stopping early. n = 1 against n = 10: the period is right long before the shape is. You cut the sum off at a small N. The question is what got left behind.
n = 1 against n = 10: the period is right long before the shape is.
References (4)

Problem solved in full

  1. Five sine waves approximating a square wave and reaching 1.182 5 steps

    Five sine waves approximating a square wave overshoot it, reaching 1.182 against the square wave's 1. Work out whether adding more terms fixes it.

    1. A square wave is odd and half-wave symmetric, which kills every even harmonic before any arithmetic happens. Five terms therefore means k = 1, 3, 5, 7, 9 — the panel's harmonic list is a consequence of the symmetry, not a setting.

    2. The partial sum overshoots near the jump. At N = 5 the peak is 1.182 and the RMS is 0.979, already close to the exact wave's RMS of 1 — so the energy is nearly right while the shape near the edge is not.

    3. Now test the obvious remedy. N = 1 peaks at 1.273, N = 5 at 1.182, N = 50 at 1.179, N = 200 at 1.17898.

    4. It is converging — but not to 1. The limit is (2/π)·Si(π) = 1.17898, and the overshoot never disappears at any number of terms.

    5. What does happen is that the overshoot gets narrower. It slides towards the discontinuity and occupies less and less width, which is why the RMS error goes to zero even though the peak error does not.

    Answer

    The tool prints N = 5, harmonics 1, 3, 5, 7, 9, a peak of 1.182 and RMS 0.979. The result to keep is that the peak converges to 1.17898, not to 1. That is the Gibbs phenomenon, and quoting it needs care: the overshoot is 8.95% of the jump — and this wave jumps by 2, from −1 to +1, so the same fact reads as 17.9% of the amplitude. Both numbers are right and neither is the other. It is also not a numerical artefact: it is what pointwise convergence looks like when the limit is discontinuous, and it is why sharp edges ring in JPEG and in audio filters.

Learning path

Circles and waves are the same motion

Example problems