Fourier series: periodic signals as harmonic sums
The puzzle: the note that isn’t there¶
A tuning fork is a resonator with a sharply defined pitch. Stand one that rings at 300 Hz next to a loudspeaker and drive the speaker with a 100 Hz square wave — the blunt on-off signal a cheap buzzer makes. The fork sings. Drive the speaker instead with a 100 Hz sine wave, at the same loudness, and the fork stays silent.
Nothing in the second signal is missing that the first has. Both repeat one hundred times a second. Both are, by any reasonable description, “a 100 Hz signal”. Yet one of them is carrying something at 300 Hz and the other is not.
There is a second version of the same puzzle you have heard all your life. A violin and a flute play the same written A. Both repeat 440 times a second, so both have the same pitch, and nobody has ever confused the two instruments. Whatever distinguishes them survives having the same period, and this module is about what that is.
Predict before you calculate¶
Commit to an answer for each of these before running anything. Write them down.
Does a resonator tuned to respond to a square-wave drive of repetition rate ? Does it respond to a sine drive at ? What about a resonator tuned to under the square drive?
A square wave is built by adding sine waves. How many terms does it take before the result is a square wave — ten, a thousand, or is there a number after which it is exact?
Zoom in on the jump while you add more and more terms. The wiggles there get narrower. Do they also get shorter, and does the overshoot go to zero?
A triangle wave and a square wave have the same period and the same peak height. Which one is reproduced better by its first five harmonics, and what feature of the waveform decides?
Explore the model¶
The laboratory notebook gives you a harmonic mixer: a slider for the size of each harmonic and another for its timing, up to thirty-two of them, with four preset waveforms to reconstruct. The waveform and its spectrum sit side by side and update together — the dual view that becomes this course’s standard way of looking at any signal, here for the first time.
A square wave assembling itself from rotating arrows. Each arrow is one harmonic’s phasor — module 00’s picture, one arrow per harmonic, the th turning times faster — laid tip to tail, and the height of the running tip traces the waveform on the right. The animation holds for one period each. Arrow lengths are not chosen: they are , so the ninth arrow is exactly a ninth of the first, and the decay of the coefficients is visible as geometry. Watch the corners sharpen as arrows are added — and watch what happens at the jump, which does not.
The jump, magnified. First the window holds still while the number of terms climbs: the ripples crowd in toward the discontinuity. Then the number of terms freezes and the window magnifies twentyfold: the same structure reappears at every scale. Through both halves the first overshoot stays on the dashed line — it is not converging to the true value, and adding terms moves it sideways rather than downwards.
Run the laboratory now, then come back. Three things are worth doing before you read on:
Build a square wave from three sliders, then five, then thirty-one, watching the spectrum panel as much as the waveform. Notice which harmonics you never need to touch.
Play the four presets through the audio cell at the same pitch. They are the same note. Your ear tells them apart instantly, and the only thing that differs is the spectrum panel.
Zoom on the jump and raise until the laboratory runs out of harmonics. Decide, from what you see rather than from what you expect, what is shrinking and what is not.
Derive the result¶
What can be in the sum. A signal of period repeats exactly. If it is to be built from sinusoids, each of those must also repeat with period , which allows only the frequencies with — the harmonics of the fundamental. Anything else would still be mid-cycle when the signal starts over. So the candidate is
with both signs of present. That is not a complication to apologise for: module 00 already showed that a real cosine is two counter-rotating exponentials, and here the pairing is , which is precisely the condition for to come out real.
Orthogonality picks out one coefficient. Everything follows from a single integral. For integer and ,
because unless the integrand is a complex exponential going through a whole number of turns, and a whole number of turns averages to nothing.
The language is worth pausing on. “Multiply and average” is an inner product; the harmonics are an orthonormal basis; is the component of along the th basis direction. The picture is the familiar one of resolving a vector into perpendicular components, with functions in place of arrows and an integral in place of a dot product. You will meet the same move again in module 07 and again in quantum mechanics.
Symmetry answers the question before the integral does. Two symmetries do most of the work in practice, and both are one substitution deep.
If is even, , the coefficient integral is unchanged under , which sends ; combined with this forces every to be real. If is odd, the same argument makes every purely imaginary. Evenness and oddness are statements about timing, and they show up as the phases of the harmonics.
Half-wave symmetry is sharper. Suppose the second half of each period is the first half turned upside down, — true of a square wave, a triangle wave, and most things that swing symmetrically about zero. Substituting into the coefficient integral multiplies term by , so . For even that reads , and the only number equal to minus itself is zero.
The square wave, worked. Take for the first half of each period and -1 for the second. It is odd and half-wave symmetric, so we already expect purely imaginary coefficients on odd harmonics only. The integral confirms it:
In real terms this is $f(t) = \frac{4}{\pi}\left(\sin\omega_0 t + \tfrac13 \sin 3\omega_0 t
\tfrac15 \sin 5\omega_0 t + \cdots\right)3\omega_04/3\pi$ comes out the other side.
Smoothness buys decay. The square wave’s coefficients fall as , which is slow. The reason is general. Integrating the coefficient formula by parts trades a factor of for a derivative of ; the boundary terms cancel by periodicity provided is continuous. So each derivative that survives without jumping buys one more power of .
| Waveform | Sharpest feature | Harmonics present | Decay |
|---|---|---|---|
| Square | jump | odd only | |
| Sawtooth | jump | all | |
| Triangle | corner | odd only | |
| Pulse train | two jumps | all, under a envelope |
The table earns its keep in the laboratory, where you measure these exponents rather than looking them up, and again in module 04, where the same statement is made about the transform of a single pulse.
Gibbs: where the series does not do what you want. Adding terms reduces the energy of the error — the mean-square distance between the partial sum and the signal goes to zero, and for the square wave it does so as . But convergence in energy is a weaker promise than it sounds, and near a jump it is not enough.
That is the answer to prediction 3, and it is worth being blunt about what it does and does not mean. It does not mean the series fails to converge — at every point away from the jump it converges perfectly well, and at the jump itself it converges to the midpoint. It means that the worst error over the whole signal does not shrink. An amplifier reproducing a square wave with a finite bandwidth really does overshoot, really does ring, and no amount of extra bandwidth removes the overshoot; more bandwidth only makes it briefer.
The resonator is a harmonic selector. Now the puzzle can be closed quantitatively. Write the periodic drive as its harmonics, each one a phasor carrying the course’s time factor .
Module 02 already solved the problem for one sinusoid: a drive of phasor at angular frequency produces a displacement of phasor divided by . Applying it harmonic by harmonic and adding,
Read what that says. The drive supplies a comb of harmonics with amplitudes falling as . The resonator multiplies each by a curve that is sharply peaked at and small everywhere else. If sits on the third harmonic, the third harmonic is amplified by roughly and the others are not: the fork rings at , a frequency the drive’s repetition rate never names. And under a pure sine drive the comb has one tooth, at , so a fork tuned to hears nothing at all.
Park the resonator on an even harmonic and the comb has no tooth there to amplify: half-wave symmetry deleted it. The response does not vanish outright — the laboratory measures about 8% of what the same resonator gives at — but what survives is the off-resonant tail of the third and fifth harmonics, not a response to a fourth. There is no fourth harmonic to respond to.
A resonator does not measure how often a signal repeats. It asks how much of the signal is at its frequency, and a Fourier series is the answer.
Verify computationally¶
Each check below is also a test in the project’s suite, so these claims cannot silently rot.
1. The closed forms against the integrals. wavelab.fourier.fourier_coefficients evaluates
the coefficient integral numerically on a sampled period; the four closed forms are compared
against it. The triangle agrees to better than 10-7. The square, sawtooth and pulse train
agree only to about one part in , the number of samples — and that gap is the same physics as
the decay table above, seen from the other side. A finite grid cannot resolve a discontinuity,
so the waveforms with jumps are the ones whose numerics are limited.
2. Convergence rates by smoothness class. The mean-square error between a partial sum and its waveform is measured for and fitted in log-log. The square wave returns an exponent of -0.49 and the triangle -1.47, against the predicted and . Both sit slightly inside their asymptotes because these orders are finite; carried to 511 harmonics they tighten to -0.495 and -1.484.
3. The overshoot that will not move.
4. The driven oscillator, two ways. The harmonic-sum prediction above is compared against a
direct velocity-Verlet integration of the same oscillator under a sampled square-wave force,
using oscillators.simulate_forced. The integrator knows nothing about harmonics — it only
knows the force at each instant — so agreement is a genuine check of the decomposition rather
than a restatement of it. The laboratory sweeps the resonator across the comb and finds the
peaks where the odd harmonics are, and near-silence between them.
Transfer the idea¶
Standing waves (module
11-standing-waves). A string clamped at both ends admits only those shapes that fit the boundary — the same discreteness argument that opened this module, with in place of . An arbitrary pluck is decomposed into modes by an integral that is orthogonality again, and each mode then evolves as its own module 01 oscillator.Timbre. The spectrum is what distinguishes a violin from a flute at the same pitch. The fundamental sets the note; the pattern of sets the instrument. Synthesizers exploit this directly, and so does every instrument maker who has ever adjusted a bore or a bridge.
Power engineering. A rectifier draws current in sharp pulses rather than sinusoids, so it injects odd harmonics back into the supply, where they heat transformers designed for 50 or 60 Hz. Harmonic limits are written into grid codes because of the decay table above.
Gratings (module
31-gratings). The pulse train’s comb of harmonics under a envelope reappears as a diffraction pattern: many sharp orders, modulated by the transform of a single slit. Same arithmetic, drawn in light.The next module. Everything here needed exact periodicity. A hand-clap never repeats, and the comb of harmonics has to become a continuum. Letting is the whole of module 04, and it starts from the formulas on this page.
Check your understanding¶
A periodic signal satisfies f(t + T/2) = -f(t): the second half of every period is the first half turned upside down. Which harmonics can it contain, and how do you know before computing any integral?
A. Odd harmonics only — every even coefficient vanishes, including the mean. B. Even harmonics only, because the waveform repeats twice within each period. C. All harmonics — a symmetry can shift the phases of the terms but cannot remove any. D. Nothing can be said without evaluating the integrals for the specific waveform.
Check your answer
Correct answer: A — Odd harmonics only — every even coefficient vanishes, including the mean.
A. Right, and it takes one substitution. Shifting the coefficient integral by T/2 multiplies term n by (-1)^n, so the symmetry forces c_n = -(-1)^n c_n. For even n that reads c_n = -c_n, and only zero equals minus itself. The square and triangle waves are both of this kind, which is why neither has a second harmonic.
B. That describes the opposite condition, f(t + T/2) = +f(t), which really is a signal of period T/2 in disguise and really does have only even harmonics of the original fundamental. The minus sign here inverts rather than repeats, and it deletes exactly the harmonics your answer keeps.
C. Evenness and oddness do only shift phases: they make the coefficients purely real or purely imaginary without deleting any. Half-wave symmetry is stronger, because it relates the signal to a shifted copy of itself rather than to a reflection, and that relation is what forces half the coefficients to zero.
D. It can, and cheaply. The substitution t -> t + T/2 inside the coefficient integral costs two lines and settles every even harmonic at once, for every waveform with this symmetry, whatever its shape. Symmetry arguments answer the question the integrals would eventually answer, before doing them.
The partial sum of a square wave’s Fourier series overshoots by about 9 percent just before the jump. What happens to that overshoot as more terms are added?
A. It narrows and slides toward the jump, but its height stays near 8.9 percent of the jump forever. B. It shrinks steadily and vanishes in the limit — more terms make the approximation better everywhere. C. It grows without limit, because each new harmonic adds another wiggle. D. It is an artefact of plotting on a finite grid and disappears with enough resolution.
Check your answer
Correct answer: A — It narrows and slides toward the jump, but its height stays near 8.9 percent of the jump forever.
A. Right. Measured, the overshoot is 9.21 percent at 7 harmonics, 8.97 percent at 31, and 8.9491 percent at 511 — settling on a constant rather than heading for zero. What does improve is the error energy, which falls as N^(-1/2). Convergence in energy and convergence at the worst point are different promises, and only the first one is kept here.
B. This is the natural expectation and it is false, which is why the overshoot has a name. The series does converge at every point away from the jump, and converges to the midpoint at the jump itself, so nothing is broken. But the largest error anywhere near the jump does not shrink. An amplifier of finite bandwidth reproducing a square wave overshoots for exactly this reason, and more bandwidth only makes the overshoot briefer, never smaller.
C. The wiggles do multiply, but they also shrink in width and the sum of their contributions is bounded. The overshoot approaches a definite constant from above, and from the very first few harmonics it is already within half a percent of its final value.
D. Refining the grid makes the measurement more accurate and the overshoot converges to 8.9491 percent rather than away from it. The opposite error is the real trap: because the overshoot moves toward the jump as terms are added, a measurement window that stays fixed eventually misses it and reports a comfortable, shrinking, wrong number.
A periodic waveform is continuous everywhere, but its slope jumps — it has corners, like a triangle wave. Its coefficients fall off as 1/n^p for large n. What is p?
Check your answer
Correct answer: 2.0 (± 0.1)
p = 2. Integrating the coefficient formula by parts trades a power of 1/n for a derivative, and the boundary terms cancel by periodicity as long as the function being differentiated is continuous. A signal that jumps gives p = 1; one that is continuous with a jumping slope gives p = 2; in general the first discontinuous derivative sets the rate. Smoother waveforms are cheaper to represent, and that is the whole content of the decay table.
A square wave of peak amplitude 1 and repetition rate f0 drives a high-Q resonator tuned exactly to 3 f0. The same resonator is then driven instead by a pure sine wave of peak amplitude 1 at its own frequency 3 f0. By what factor is the steady-state amplitude in the first case smaller than in the second? Give the ratio (first case) / (second case).
Check your answer
Correct answer: 0.424 (± 0.02)
The resonator responds only to what the drive carries at its own frequency. A unit square wave carries 4/(3 pi) = 0.4244 at its third harmonic, against the 1.0 the pure sine supplies, and since both drives sit on resonance the response curve multiplies both by the same gain. So the ratio is just the harmonic amplitude, 0.42. Tuned to 2 f0 instead there would be no resonant response at all, because half-wave symmetry deletes every even harmonic and the drive carries exactly nothing there — what little such a resonator does is the off-resonant tail of its neighbours, about a tenth of what it manages at 3 f0.
Four spectra are measured. (i) all harmonics present, amplitudes falling as 1/n. (ii) odd harmonics only, falling as 1/n. (iii) odd harmonics only, falling as 1/n^2. (iv) all harmonics present, nearly equal in size out to very high n. Which is the sawtooth?
A. (i) — a jump forces the slow 1/n decay, and the lack of half-wave symmetry keeps the even harmonics. B. (ii) — the classic jump waveform, so odd harmonics decaying as 1/n. C. (iii) — the ramp is continuous within the period, so its coefficients fall as 1/n^2. D. (iv) — every harmonic present in comparable strength, since the ramp visits every value equally.
Check your answer
Correct answer: A — (i) — a jump forces the slow 1/n decay, and the lack of half-wave symmetry keeps the even harmonics.
A. Right, and the pair of clues is what pins it. The 1/n decay says there is a jump somewhere in the period; the presence of even harmonics says the second half of the period is not the inverted first half. Only the sawtooth satisfies both. For the record: (ii) is the square wave, (iii) the triangle, and (iv) a narrow pulse train, whose sinc envelope is still wide at these harmonics.
B. The 1/n decay is right, and for the right reason, but a sawtooth has no half-wave symmetry: shifting it by half a period does not give you minus itself, it gives a differently offset ramp. So its even harmonics survive. Spectrum (ii) belongs to the square wave.
C. The ramp is continuous within a period but the waveform is periodic, and at the end of every period it drops discontinuously back to its starting value. That jump is what the coefficients see, and it fixes the decay at 1/n. Spectrum (iii), with its 1/n^2 decay and odd harmonics only, is the triangle wave.
D. Visiting every value has nothing to do with the harmonic content; what matters is the sharpness of the features. A spectrum this flat belongs to something much sharper than a ramp — a narrow pulse train, whose sinc envelope has not yet turned over at these harmonics. The sawtooth’s amplitudes fall steadily as 1/n.
A measurement of a periodic signal returns a third coefficient with magnitude |c_3| = 0.25 and argument arg(c_3) = -pi/2. State what each of those two numbers asserts physically, and describe an experiment that would confirm each one separately.
Check your answer
The magnitude fixes the size of the third harmonic: its phasor is 2 c_3* , so the signal contains a sinusoid at 3 omega0 of amplitude 2 |c_3| = 0.5. The argument fixes that harmonic’s timing — where in the cycle it peaks relative to t = 0 — and nothing else. To confirm the magnitude, put a narrow filter or a lock-in amplifier tuned to 3 omega0 in front of the signal and measure the amplitude that emerges: it should be 0.5, and it is there whether or not anyone chose to decompose the signal. To confirm the argument you need a phase reference, because the argument alone is not an invariant: shift the origin of time by delta and every arg(c_n) shifts by n omega0 delta while every |c_n| is untouched. So the measurable statement is a phase difference — between this harmonic and the fundamental, or between this harmonic and an external trigger — exactly as module 00 argued for a single oscillation. That distinction between what the magnitudes carry and what the phases carry is the seed of the question module 04 asks about whether a spectrum remembers when things happened.
Exam-style problems for this module — the ones worth doing with a pen — are collected in the problem set.
Explain it in your own words¶
Answer in a few sentences each. These are the questions that reveal whether the ideas landed; no number will save you.
A clarinet and a violin play the same written A. Both signals repeat 440 times a second. Explain what physically differs between them, and why “they have different pitches” is the wrong answer.
A sceptic says: “Saying a square wave contains 300 Hz is just a way of talking — it is one signal at 100 Hz, and the harmonics are bookkeeping.” Answer them using the resonator experiment, and be clear about what would have to happen for the sceptic to be right.
An amplifier is described as overshooting by 9% when fed a square wave. A colleague proposes fixing it by extending the bandwidth. What will that actually change, and what will it not?
Which bullet of the model specification forbids applying this module’s machinery to the sound of a single hand-clap, and what goes wrong if you ignore it?
Advanced: what “equals” is doing in that equation¶
Two senses of convergence. Writing hides a choice. The series converges to in mean square: the energy of the difference goes to zero, which is the sense Parseval measures and the sense the rate describes. It does not converge uniformly near a jump — the largest pointwise error stays stubbornly at 9% of the jump — and Gibbs is exactly the gap between those two statements. For continuous, piecewise-smooth signals the two senses agree and the distinction never surfaces; it surfaces here because a jump is precisely the case where they part company.
Averaging beats truncating. The overshoot is a property of the sharp cutoff, not of the harmonics. Replace the partial sum by the average of all partial sums up to — the Fejér, or Cesàro, sum — and the overshoot vanishes entirely, with convergence now uniform. The cost is paid at the edges: the Fejér sum is smoother than the signal and rounds the corners it is trying to reproduce. This is the same trade every window function makes, and module 04 meets it again under the name of spectral leakage.
The negative half. Under the course convention the th harmonic’s phasor is , which is to say the negative-index coefficient carries it: . The clockwise half of the sum is module 00’s rotating arrow, and the counter-clockwise half is its mirror, required only to keep the total real. Keeping one half alone gives the analytic signal that module 00’s advanced section previewed. Module 04 closes the thread — and shows that the same asymmetry is why the spectrum of a real cosine puts its phasor at rather than at .