Skip to content
ScienceQuest
Maths & Data Visualiser Undergraduate

Fourier Series Visualiser

Watch a Fourier series build a square, sawtooth or triangle wave from sine harmonics as circles draw it, and the Gibbs overshoot, 9% of the jump, stay.

Visualiser

Add or remove a term with the up and down arrow keys. Space plays and pauses.

t = 0.00 T
Overshoot
How far the sum’s highest point rises above the top of the wave, as a share of the jump from +1 to −1. More terms take it towards 8.95 percent, not to zero.
9.12 % of the jump
Highest point
Of the sum over a whole period. The wave itself tops out at 1, and beside a jump the peak heads for 1.179 rather than for 1.
1.182
Peak position
π/(n + 1) before the jump, with n = 9 the highest harmonic. It closes in on the jump as terms are added, while its height heads for 1.179 rather than for 1.
1/20 period before the jump
Highest harmonic
5 terms: harmonics 1, 3, 5, 7 and 9. Even harmonics are all zero for this wave.
9
Power left out
The share of the wave’s mean square carried by the harmonics not yet added, from Parseval’s theorem. It falls towards zero even where the overshoot does not.
4.04 %
RMS error
Root mean square of the gap between the sum and the wave over one period, in units of the wave’s height.
0.201
Parameters

Each term adds one harmonic. With the scene focused, the up and down arrow keys add and remove them.

The first eight terms, faintly, under the sum they add up to.

Odd harmonics only, each 1/n as strong. Watch the ripple beside each jump get narrower as terms are added, but hardly any lower.

  • Highest point of the sum
  • Top of the wave
  • Gibbs limit, 1.179
The highest point of the sum against the number of terms, with the top of the wave and the Gibbs limit dashed. For a wave with a jump the peak settles near 1.179, about 9 percent of the jump above the top of the wave, instead of on the top itself.
Square wave: bₙ = 4/(nπ) for odd n, and 0 for even n.
nbₙbₙ ÷ b₁Share of power
11.273181.1 %
30.42441/39.01 %
50.25461/53.24 %
70.18191/71.65 %
90.14151/91 %

Citing this tool

Last updated . Add the date you accessed it as well, which a citation of a page that can change asks for. If a specific result matters, cite the permalink from the tool’s share row instead of this page: it reproduces the exact parameters.

Teaching with this? You can put it on a class page or LMS for free, with no ads inside the frame. Get the embed code.

The equation

f(x)=4Aπ∑n odd1nsin⁡nxf(x) = \frac{4A}{\pi}\sum_{n\,\text{odd}} \frac{1}{n}\sin nx

Fourier, Théorie analytique de la chaleur (1822)

A square wave is a sum of odd sine waves

A Fourier series writes a repeating wave as a sum of sine and cosine waves whose frequencies are whole-number multiples of the wave’s own. A square wave that switches from −A to +A at x = 0 needs only sines, and only the odd ones:

f(x) = (4A/π)(sin x + (1/3) sin 3x + (1/5) sin 5x + …)

Here x runs through 2π in one period, so x = 2πt/T for a wave of period T, and harmonic n goes through n cycles in each period of the wave. Its amplitude is 4A/(nπ): the third harmonic is a third as strong as the fundamental and the fifth a fifth. The other two waves here follow the same pattern with different coefficients:

  • Sawtooth, a steady rise from −A to +A and a sudden drop back, once a period: f(x) = (2A/π)(sin x − (1/2) sin 2x + (1/3) sin 3x − …), every harmonic, with alternating signs.
  • Triangle, which peaks a quarter of the way through each period, at +A: f(x) = (8A/π²)(sin x − (1/9) sin 3x + (1/25) sin 5x − …), odd harmonics only, each 1/n² as strong.

Each coefficient is one integral over a period, bₙ = (1/π) × the integral of f(x) sin(nx), which measures how much of the wave lines up with that one harmonic. It is an integral of the kind the Riemann Sum and Integral Explorer builds out of strips. The table under the plot lists the coefficients in your sum, with the share of the wave’s power each one carries.

Reading the circles

Each harmonic is drawn as a circle with two arms of equal length, one turning forwards and one turning back, both at n turns per period for harmonic n. The circle’s radius is half the harmonic’s amplitude, |bₙ|/2. The two arms’ sideways movements cancel exactly and their vertical movements add, so every pair ends back on the centre line, raised or lowered by bₙ sin(nx). The small dots on that line are the running total after each of the first twelve terms, the larger dot where the chain ends is the whole sum, and the dotted line carries its height across to the pen.

That pairing is the complex form of the series, in which each harmonic appears twice, once as cₙe^(inx) turning one way and once as c₋ₙe^(−inx) turning the other. A real wave always has both halves. Drawn with a single circle per harmonic instead, the tip would also swing from side to side by Σ bₙ cos(nx), and for a wave with a jump that swing grows without limit as terms are added, which moves the drawing about without changing the height the pen traces.

The same harmonics are physical in a vibrating string. The Standing Wave Simulator shows a string’s modes one at a time, and a real pluck sets several of them going at once, which is a sum of exactly this kind. A string plucked at its midpoint starts in the shape of the first half of the triangle wave here, so the modes it sets going are that wave’s odd harmonics, with amplitudes falling as 1/n².

What the readouts mean

  • Overshoot is how far the sum’s highest point rises above the top of the wave, as a percentage of the jump. It reads “none yet” while the sum still peaks below the top, as a sawtooth does with four terms or fewer, and “none” for the triangle wave, which has no jump.
  • Highest point is the top of the sum over a whole period, in units of the wave’s height, and Peak position says where it is: 1/(2(n + 1)) of a period before the jump, with n the highest harmonic. The Go to the peak button pauses the pen there.
  • Highest harmonic is the largest n in the sum. Five terms of a square wave reach harmonic 9, because its even harmonics are all zero, while five terms of a sawtooth reach harmonic 5.
  • Power left out is the share of the wave’s mean square that the missing harmonics carry, from Parseval’s theorem, and RMS error is the root mean square gap between the sum and the wave over one period. Both fall towards zero as terms are added, even though the overshoot does not.

The option to draw each harmonic on its own lays the first eight terms faintly under the sum, so you can see what each one adds. With the scene focused, the up and down arrow keys add and remove terms.

Worked example: five terms of a square wave

Take a square wave of height 1, switching between −1 and +1, and its first five terms, the harmonics 1, 3, 5, 7 and 9, which is where the visualiser opens:

S(x) = (4/π)(sin x + sin(3x)/3 + sin(5x)/5 + sin(7x)/7 + sin(9x)/9)

The highest harmonic is 9, so the sum’s highest point sits π/(9 + 1) = π/10 before the jump at x = π, at x = 0.9π, which is a twentieth of a period. There the five terms inside the bracket are 0.3090, 0.2697, 0.2000, 0.1156 and 0.0343. They add to 0.9286, and times 4/π that is 1.1823.

The wave itself is 1 there, and the jump it is approaching runs from +1 down to −1, a height of 2. So the sum overshoots the top by 0.1823, and dividing by the jump gives 0.1823/2, which is 9.12 percent of the jump, as the readout says. The same five terms carry 96.0 percent of the wave’s power, which leaves an RMS error of 0.201. To check the peak by a second route, type (4/pi)(sin(x) + sin(3x)/3 + sin(5x)/5 + sin(7x)/7 + sin(9x)/9) into the Graphing Calculator and trace the curve near x = 2.83, which is 0.9π, where it tops out at 1.182.

The overshoot that more terms never remove

Add terms and the ripple beside the jump gets narrower, but its peak barely comes down. At ten terms it is 8.99 percent of the jump and at fifty it is 8.95 percent. It heads for a fixed fraction of the jump, Si(π)/π − 1/2 = 0.0895, where Si is the sine integral and Si(π) = 1.8519 is known as the Wilbraham-Gibbs constant, so the peak of a wave of height 1 settles near 1.179 rather than on 1. What more terms do change is where the peak sits: π/(n + 1) before the jump, with n the highest harmonic, so it closes in on the jump without ever reaching it. The plot under the circles shows the whole story, the highest point flattening onto the Gibbs line rather than onto the top of the wave.

None of that contradicts the series converging. At any one point away from the jump the sum does settle on the wave, and the mean square error falls towards zero: the power left out is 4.04 percent at five terms and 0.405 percent at fifty. It is the largest error over the whole period that refuses to shrink, because the peak keeps moving to a new point as terms are added. That is the difference between converging at every point and converging uniformly, and a jump is exactly what rules out the second. The NIST Digital Library of Mathematical Functions sets out the same overshoot for this square wave in its section 6.16.

Henry Wilbraham described the overshoot in 1848, but his paper went largely unnoticed. It came to attention through J. Willard Gibbs’s letters to Nature in 1898 and 1899, the second of which describes it, and Maxime Bôcher gave it Gibbs’s name in 1906. Edwin and Robert Hewitt tell the whole story, with the sources, in the Archive for History of Exact Sciences (1979).

The sawtooth gets there late

Switch to the sawtooth and the overshoot is missing at first. One term peaks at 0.637, four at 0.972, and only at five terms does the sum rise above the top of the wave, to 1.008. From there it creeps upwards, to 7.97 percent of the jump at fifty terms, towards the same 8.95 percent limit as the square wave.

The reason is the slope. The peak sits π/(n + 1) before the jump, and there the sawtooth itself is already 1/(n + 1) below its top, so an overshoot measured against the top starts in a hole it has to climb out of. Measured against the wave at the same point instead, it is 8.88 percent at ten terms and 8.95 percent at fifty. Gibbs’s first letter, in 1898, was about the partial sums of a sawtooth series, and it was his correction the following year that described the overshoot.

Why the triangle wave settles so fast

The triangle wave has corners but no jumps, and its coefficients fall as 1/n² rather than 1/n. That is the general rule: a jump anywhere in a wave makes its coefficients fall off as 1/n, and a wave that is continuous but has corners gets 1/n². The difference is large. The fundamental alone carries 98.6 percent of a triangle wave’s power, against 81.1 percent for the square wave and 60.8 percent for the sawtooth, and five terms leave an RMS error of 0.0073 on the triangle against 0.201 on the square.

There is no overshoot to watch, because there is no jump. The sum reaches each corner from below instead: one term gets to 8/π² = 0.811, five get to 0.960, and the value at the corner climbs to 1 because 1 + 1/9 + 1/25 + … adds up to exactly π²/8.

The two waves are also related by calculus. Differentiate the triangle series term by term and it becomes a square wave of height 2/π, which is the triangle’s slope, in cosine form. The Derivative and Tangent Line Explorer draws the same idea for smooth curves, a function’s gradient traced out as a curve of its own.

Odd harmonics, and where the symmetry comes from

The square and triangle waves have no even harmonics at all, and the reason is a symmetry you can see: the second half of each period is the first half turned upside down, f(x + π) = −f(x). An even harmonic repeats itself exactly after half a period instead of changing sign, so what it picks up from the first half of the wave the second half cancels, and its coefficient comes out as zero. The sawtooth has no such symmetry, so every harmonic appears in it.

There are no cosine terms in any of the three for a similar reason: each is drawn as an odd function, f(−x) = −f(x), which only sines can build. Shift the triangle wave a quarter period so that it peaks at x = 0 and it becomes even, its series turns into cosines, and the alternating signs disappear: (8A/π²)(cos x + (1/9) cos 3x + (1/25) cos 5x + …).

What this model leaves out

The three waves are ideal: their jumps take no time at all and their corners are perfectly sharp. A real signal switches in a finite time, so its harmonics fade out faster than these do, and a real circuit or loudspeaker passes some harmonics more readily than others. Measured waveforms differ from these sums in ways this does not model.

Every wave here is centred on zero and drawn as an odd function, with a jump or a zero crossing at x = 0, which is what makes its series pure sines. A wave shifted in time needs cosine terms as well, and a wave that is not centred on zero needs a constant term: a square wave between 0 and 1 is 1/2 + (2/π)(sin x + (1/3) sin 3x + …), half of each coefficient here with a half on top.

The sums are the raw partial sums, cut off sharply after the last term. Averaging the partial sums, which is Fejér’s method, removes the overshoot completely at the cost of a slower rise at the jump, and gentler cut-offs such as Lanczos’s sigma factors shrink it. None of that is applied here, because the overshoot of the raw sum is the thing on show.

Common mistakes

  • Expecting enough terms to remove the overshoot. They make it narrower, but hardly any lower. Beside a jump the sum stays about 9 percent of the jump too high, however many terms it has.
  • Quoting the overshoot against the wrong height. It is about 9 percent of the jump. For a square wave between −1 and +1 the jump is 2, so the sum peaks near 1.18, which is 18 percent above the top of the wave.
  • Giving a square wave even harmonics. Its half-wave symmetry makes every one of them zero, so the terms are sin x, sin 3x, sin 5x and so on.
  • Dropping the alternating signs. The sawtooth’s coefficients alternate between plus and minus, and so do the triangle wave’s in the sine form drawn here. Leave the signs out and the terms add up to a different wave.
  • Forgetting the constant term. A wave that does not average to zero, such as a square wave between 0 and 1, needs a₀/2, its mean value, before any sines.
  • Expecting the wave’s value at a jump. The series takes the midpoint there, 0 for a wave that jumps between −1 and +1, and every partial sum drawn here passes through it.

Common questions

What is the Fourier series of a square wave?

It is the sum of its odd harmonics, (4A/π)(sin x + (1/3) sin 3x + (1/5) sin 5x + …), for a square wave that jumps from −A to +A at x = 0 and back at x = π, repeating every 2π. Harmonic n has amplitude 4A/(nπ), so the third is a third as strong as the fundamental and the fifth a fifth, and no even harmonic appears at all. The fundamental alone carries 81.1 percent of the wave’s power, and five terms carry 96.0 percent.

What is the Gibbs phenomenon?

It is the overshoot a Fourier series makes next to a jump, about 9 percent of the jump, which adding terms never removes. With five terms the square wave’s sum peaks at 1.182 against a top of 1, which is 9.12 percent of the jump from −1 to +1, and with fifty terms it is still 8.95 percent. The limit is Si(π)/π − 1/2 = 0.0895, where Si is the sine integral. More terms squeeze the peak towards the jump, to π/(n + 1) from it when n is the highest harmonic, but hardly lower it. Henry Wilbraham described it in 1848 and J. Willard Gibbs in a letter to Nature in 1899, and Maxime Bôcher gave it its name in 1906.

What does a Fourier series converge to at a discontinuity?

The midpoint of the jump: at a discontinuity the series converges to the average of the values on either side, which is 0 for a wave that jumps between −1 and +1. Dirichlet proved this in 1829 for any wave with finitely many jumps and finitely many peaks and troughs in a period. For the square and sawtooth waves every partial sum passes exactly through that midpoint too, because every sine term is zero at the jump, which is why the drawn sum always crosses a jump at half height.

Why does a square wave have only odd harmonics?

Because its second half is its first half turned upside down, f(x + π) = −f(x), and an even harmonic cannot follow that pattern. An even harmonic repeats itself exactly every half period instead of changing sign, so its contributions from the two halves of the wave cancel and its coefficient integrates to zero. The triangle wave has the same half-wave symmetry and so has only odd harmonics too, while the sawtooth does not and uses every harmonic, with alternating signs.

Why does the triangle wave converge so much faster than the square wave?

Because it has corners but no jumps, and that makes its coefficients shrink as 1/n² instead of 1/n. A wave with a jump has coefficients that fall off as 1/n, while a continuous wave whose slope jumps has coefficients that fall off as 1/n². The fundamental alone carries 98.6 percent of a triangle wave’s power, against 81.1 percent for a square wave and 60.8 percent for a sawtooth, and five terms leave an RMS error of 0.0073 on the triangle against 0.201 on the square.