Skip to content

9.2 — Fourier Series

In 1807 Joseph Fourier submitted a paper to the French Academy of Sciences claiming that any periodic function — including ones with corners and jumps — could be written as a sum of sines and cosines.

The judging panel included Lagrange, Laplace and Legendre, three of the greatest mathematicians alive. Lagrange objected strongly and blocked publication. The claim seemed absurd: sines and cosines are smooth and infinitely differentiable, so how could adding them ever produce a sharp corner, let alone a vertical jump?

The paper was rejected. Fourier published it as a book in 1822, and he was essentially right — with conditions that took another century to state precisely. The objection was not stupid, and understanding why it was raised is the best way to understand what a Fourier series actually does.

Portrait of Joseph Fourier
Jean-Baptiste Joseph Fourier (1768–1830). He developed these series while studying heat conduction, accompanied Napoleon to Egypt as a scientific adviser, and was also the first person to describe what we now call the greenhouse effect. Image: Wikimedia Commons.

1. The series

For a function with period 2\pi:

f(x) = \frac{a_0}{2} + \sum_{n=1}^{\infty}\big[a_n\cos(nx) + b_n\sin(nx)\big]

The frequencies are whole-number multiples of the fundamental. n=1 is the fundamental, and n=2,3,4,\ldots are the harmonics.

The coefficients come straight from Chapter 9.1's orthogonality. Multiply by the basis function you want and integrate:

a_n = \frac1\pi\int_{-\pi}^{\pi}f(x)\cos(nx)\,dx, \qquad b_n = \frac1\pi\int_{-\pi}^{\pi}f(x)\sin(nx)\,dx

Every other term drops out, because everything else is orthogonal. Each coefficient is computed independently, with no reference to the others, which is what makes the whole scheme practical.

a_0/2 is the average value of the function — the DC component, a name borrowed from electronics where it means the direct-current offset.

Symmetry shortcuts, worth knowing because they halve the work. If f is even (symmetric about the vertical axis) all the b_n vanish, leaving only cosines. If f is odd, all the a_n vanish, leaving only sines. Chapter 3.5 defined even and odd.

2. The square wave, worked

A square wave that is +1 on (0,\pi) and -1 on (-\pi,0). It is odd, so only sines survive.

b_n = \frac1\pi\int_{-\pi}^{\pi}f(x)\sin(nx)dx = \frac2\pi\int_0^\pi\sin(nx)dx = \frac{2}{n\pi}\big[1-\cos(n\pi)\big]

Now \cos(n\pi) is -1 for odd n and +1 for even n. So even harmonics vanish entirely and odd ones give \frac{4}{n\pi}:

f(x) = \frac4\pi\left(\sin x + \frac{\sin3x}{3}+\frac{\sin5x}{5}+\frac{\sin7x}{7}+\cdots\right)

Only odd harmonics, with amplitudes falling as \frac1n.

A square wave with successive Fourier partial sums drawn over it
Partial sums approaching a square wave. One term is a plain sine; three terms already show flat tops beginning to form; by a few dozen terms it is visually a square wave, with ripples surviving at the jumps. Image: Wikimedia Commons.

Watch what each term does. The first sine gets the overall shape. The third harmonic flattens the tops and steepens the sides. The fifth sharpens further. High frequencies build the sharp features, which is the general rule and the reason Chapter 6.4's heat equation destroys sharpness first — it damps high harmonics fastest.

Rotating circles of decreasing size whose combined motion traces a square wave
The same series as rotating circles. Each circle is one harmonic — its radius the amplitude, its rotation speed the frequency — and stacking them traces the square wave. This is Chapter 3.5's picture of a sine as a rotation seen from the side, several times over. Image: Wikimedia Commons.

A bonus. Set x = \frac\pi2, where the square wave equals 1 and the sines take values 1, -\frac13, \frac15, \ldots:

1 = \frac4\pi\left(1-\frac13+\frac15-\frac17+\cdots\right)

which gives the Leibniz–Madhava series for \pi from Chapter 3.3, falling out of a completely unrelated calculation.

The claim that those odd harmonics add up to a square wave is easier to believe when you watch it happen one harmonic at a time.

At N = 0 there is a single sine wave, nothing like a square. Each new odd harmonic flattens the top a little further and steepens the sides. By N = 20 it is unmistakably square, except at the jumps, where an overshoot of about 9% refuses to go away however many terms you add.Drag the sliders; hover the curve to read exact values.

Watch the corners rather than the flat parts. The overshoot beside each jump gets narrower as N rises but never gets shorter, and that is the phenomenon the next section is about.

3. Where Lagrange was right

Fourier's claim needed conditions, and the honest statement is the Dirichlet conditions, proved in 1829. If a periodic function is bounded, has finitely many maxima and minima, and finitely many discontinuities in each period, then its Fourier series converges to the function everywhere it is continuous — and at a jump, it converges to the midpoint of the jump.

That last clause matters. The series does not reproduce the function at a discontinuity; it splits the difference. Our square wave at x=0 jumps from -1 to +1, and every term of the series is zero there, so the series gives 0 — the midpoint.

The Gibbs phenomenon

Near a jump, the partial sums overshoot. Add more terms and the overshoot gets narrower but not smaller — it settles at about 9% of the jump height and stays there forever.

Michelson built a machine in 1898 to compute Fourier series mechanically and saw these ripples. He assumed his machine was faulty and wrote to Gibbs, who explained in 1899 that the effect is real mathematics, not a mechanical defect.

Why it happens: a finite sum of smooth functions cannot turn a corner instantly, so it overshoots. As terms are added, the overshoot compresses towards the jump but its height does not shrink.

Where you have seen it. Ringing artefacts around sharp edges in a heavily compressed JPEG. Overshoot on a fast electrical pulse passing through a band-limited channel. The pre-echo in some audio codecs. It is the same phenomenon each time, and knowing the name means recognising that the fix is to change the basis or window the transform, not to add more terms.

4. The complex form

Euler's formula from Chapter 2.5 collapses the sines and cosines into one expression:

f(x) = \sum_{n=-\infty}^{\infty}c_ne^{inx}, \qquad c_n = \frac{1}{2\pi}\int_{-\pi}^{\pi}f(x)e^{-inx}dx

One coefficient per frequency instead of two, and one formula instead of two. The price is that n now runs over negative values as well, which sounds like a bug and is the natural bookkeeping: a real signal has c_{-n} = \overline{c_n}, and the pair of conjugates carries exactly the amplitude and phase that a_n and b_n carried between them.

This is the form every engineer and every algorithm uses, because the algebra is far cleaner. The magnitude |c_n| is the amplitude at that frequency and the argument is the phase.

5. What this tells you about sound

Musical timbre. A violin and a flute playing the same note produce the same fundamental frequency and different harmonic content. The flute is nearly a pure sine, with weak harmonics. The violin is rich in them. That harmonic recipe is what you recognise as the instrument, and it is why you can identify a voice from two syllables.

Why some waveforms sound harsh. A square wave contains only odd harmonics falling off slowly as \frac1n, so it is buzzy. A triangle wave has odd harmonics falling as \frac{1}{n^2} — much gentler, much softer. Smoothness in the waveform means faster decay of the harmonics, and that is a general rule: the smoother the function, the faster its Fourier coefficients shrink.

Why a clarinet sounds hollow. A cylindrical pipe closed at one end suppresses even harmonics, so it produces something like a square wave's spectrum. A conical instrument such as the oboe has all harmonics and sounds quite different.

Synthesisers. Additive synthesis builds a sound by adding sine waves with chosen amplitudes — a Fourier series run forwards. Subtractive synthesis starts with a harmonically rich waveform and filters harmonics away. Both are this chapter, applied.

Your ear does this in hardware. The cochlea is a tapered tube whose different positions resonate at different frequencies, so different hair cells fire for different frequencies. Your ear is a mechanical Fourier analyser, and that is why you hear a chord as three notes rather than one complicated pressure wave.

6. Solving a differential equation with it

This is what Fourier invented the series for. A metal bar of length L held at zero temperature at both ends, with some starting profile.

Chapter 6.4 found the building-block solutions:

u_n(x,t) = \sin\!\left(\frac{n\pi x}{L}\right)e^{-\alpha(n\pi/L)^2t}

Each satisfies the heat equation and the boundary conditions. Because the equation is linear, any sum of them does too:

u(x,t) = \sum_n b_n\sin\!\left(\frac{n\pi x}{L}\right)e^{-\alpha(n\pi/L)^2t}

At t=0 the exponentials are all 1, so the initial profile must equal \sum b_n\sin(n\pi x/L) — a Fourier sine series, and the b_n are its coefficients.

So the whole method is: decompose the starting shape into harmonics, let each harmonic decay at its own rate, add them back up.

And the n^2 in the exponent is the physical punchline. Doubling the frequency quadruples the decay rate. Sharp features vanish almost immediately and the broad shape persists for a long time, which is exactly what you observe when a hot spot spreads out.

Every formula above, built from scratch

None of the results in this chapter are worth memorising, because each one can be rebuilt in under a minute from something simpler. What follows is that rebuilding, one result at a time, so the formula and the reason for it sit on the same page as the explanation that needed them.

Fourier series

f(x) = \frac{a_0}{2}+\sum_{n=1}^{\infty}\left[a_n\cos(nx)+b_n\sin(nx)\right]

a_n = \frac1\pi\int_{-\pi}^{\pi}f(x)\cos(nx)\,dx, \qquad b_n = \frac1\pi\int_{-\pi}^\pi f(x)\sin(nx)\,dx

Where the coefficient formulas come from — this is the payoff of §1. Assume the expansion is valid. Multiply both sides by \cos(mx) and integrate from -\pi to \pi:

\int_{-\pi}^\pi f(x)\cos(mx)dx = \frac{a_0}{2}\int\cos(mx)dx + \sum_n a_n\int\cos nx\cos mx\,dx + \sum_n b_n\int\sin nx\cos mx\,dx

Now apply the three orthogonality results. The first integral is zero (for m\ge1). Every sine–cosine integral is zero. Every cosine–cosine integral is zero except the single term where n=m, which contributes \pi. The infinite sum collapses to one term:

\int_{-\pi}^\pi f(x)\cos(mx)\,dx = a_m\pi

Divide by \pi. The same argument with \sin(mx) gives b_m.

What just happened. Orthogonality acted as a filter: it killed every term but one, so a coefficient buried inside an infinite sum could be pulled out by a single integral. This is the same move as taking a dot product with a basis vector in 4.6 — svd and pca §7 — the functions \sin nx and \cos nx are a perpendicular coordinate system for the space of functions, and the coefficients are the coordinates.

For a general period L

f(x) = \frac{a_0}{2}+\sum_{n=1}^\infty\left[a_n\cos\frac{2\pi nx}{L}+b_n\sin\frac{2\pi nx}{L}\right]

a_n = \frac2L\int_0^Lf(x)\cos\frac{2\pi nx}{L}dx, \qquad b_n = \frac2L\int_0^Lf(x)\sin\frac{2\pi nx}{L}dx

Symmetry shortcuts that halve the work

f \text{ even } (f(-x)=f(x)) \;\Rightarrow\; \text{all } b_n = 0 \quad\text{(cosines only)}

f \text{ odd } (f(-x)=-f(x)) \;\Rightarrow\; \text{all } a_n = 0 \quad\text{(sines only)}

Why. Cosine is even and sine is odd. An odd function cannot contain any even ingredient, because the sum would not be odd. Checking the symmetry of f before computing anything can save half the integrals.

The three standard series

Square wave (odd, amplitude 1, period 2\pi):

f(x) = \frac4\pi\left(\sin x + \frac{\sin3x}{3}+\frac{\sin5x}{5}+\cdots\right) = \frac4\pi\sum_{k=0}^\infty\frac{\sin\left((2k+1)x\right)}{2k+1}

Sawtooth:

f(x) = 2\left(\sin x - \frac{\sin2x}{2}+\frac{\sin3x}{3}-\cdots\right)

Triangle wave:

f(x) = \frac{8}{\pi^2}\left(\sin x - \frac{\sin3x}{9}+\frac{\sin5x}{25}-\cdots\right)

Read the coefficients as a description of the sound. The square wave's terms fall off like \frac1n — slowly, so it is rich in high harmonics and sounds harsh and buzzy. The triangle's fall off like \frac{1}{n^2} — much faster, so it is nearly a pure tone and sounds soft. Sharper corners need more high frequencies, and that single rule connects the shape of a waveform to the character of a sound.

At N = 0 there is one sine wave, nothing like a square. Each new odd harmonic flattens the top a little more and steepens the sides. By N = 20 it is unmistakably square — except at the jumps, where an overshoot of about 9% refuses to go away no matter how many terms you add. That is the Gibbs phenomenon, and the important part is that the overshoot gets narrower but never shorter. It is the reason a sharp edge in a digital image, or a hard clip in audio, produces ringing.Drag the sliders; hover the curve to read exact values.

The Gibbs phenomenon, seen above: near a jump discontinuity, the partial sums overshoot by about 8.95% of the jump size, forever. More terms squeeze the overshoot into a narrower spike but never reduce its height. It is not an error in the series — the series converges correctly at every individual point — it is a fact about how the convergence happens.

Complex form, which is tidier

f(x) = \sum_{n=-\infty}^{\infty}c_ne^{inx}, \qquad c_n = \frac{1}{2\pi}\int_{-\pi}^\pi f(x)e^{-inx}dx

Where it comes from. Euler's formula lets \cos and \sin be written as combinations of e^{inx} and e^{-inx}. Collecting terms turns the two real families into one complex family, and the relation to the real coefficients is

c_n = \frac{a_n-ib_n}{2}, \qquad c_{-n} = \overline{c_n}

One formula replaces two, at the price of negative frequencies — which are not physical, but are exactly what is needed for the algebra to be symmetric.

Parseval's theorem

\frac{1}{2\pi}\int_{-\pi}^{\pi}\left|f(x)\right|^2dx = \sum_{n=-\infty}^\infty |c_n|^2 = \frac{a_0^2}{4}+\frac12\sum_{n=1}^\infty\left(a_n^2+b_n^2\right)

What it says. The total energy in the signal equals the total energy in its frequency components. Nothing is created or lost by the transformation — it is a change of coordinates, and like any rotation it preserves length. This is the Pythagorean theorem in a space with infinitely many perpendicular directions.

One famous consequence. Apply Parseval to the sawtooth and the identity collapses to

\sum_{n=1}^\infty\frac{1}{n^2} = \frac{\pi^2}{6}

which is the Basel problem Euler solved in 1735, told in 11.1.

7. Where this shows up in your life

Every note you hear and every voice you recognise. Harmonic content.

Every audio equaliser. Boosting the bass means increasing the low-frequency coefficients.

Every guitar tuner and every pitch-detection app.

Every image and audio compression format. Chapter 9.3 covers the discrete version that actually runs.

Every vibration analysis in engineering. A rotating machine's spectrum tells you which part is failing, because each defect has a characteristic frequency.

Every electrical power system. Harmonic distortion from non-linear loads is a real and regulated problem, measured in exactly these coefficients.


Fourier series work for periodic functions. Most real signals are not periodic — a spoken word happens once. Extending the idea to those requires letting the period become infinite, and what comes out is the transform that runs the modern world.