Computer Systems Modelling · Section 5.6 · Interactive lab

The Fourier series

An eternal periodic signal can be written as a sum of sinusoids whose frequencies are multiples of the fundamental frequency. This lab builds periodic signals from their harmonics, shows the same sum as a chain of rotating phasors, and works through Example 5.9, whose coefficients lie on a sinc curve. That curve leads straight to the Fourier transform of Section 5.7.

How it works and what to try

How it works: In three tabs. (1) Sum of harmonics: pick a square, triangle, sawtooth or pulse wave, or draw your own period, and add harmonics one at a time, with the coefficients of Equation 5.31 shown as a table and a bar chart. (2) Phasors and the complex form: see one harmonic as two phasors a quarter turn apart, drawn as helices in three dimensions, then a whole chain of phasors whose tip traces out the signal, in either the sinusoidal or the complex form (Equations 5.32 and 5.33). (3) Example 5.9: vary the width τ and period T0 of a pulse train and watch its coefficients move along the sinc envelope of Equation 5.36.

Try this: Add harmonics to the square wave and see that the overshoot at each jump stays near 9% however many you add (the Gibbs phenomenon). Compare how fast the square and triangle waves converge. Switch between the two forms and see that only the complex one keeps the tip on the real axis. Double T0 in Example 5.9 and see the samples crowd together while the zero crossings stay put.

Section, example and equation numbers refer to Chapter 5 of S. Keshav, Mathematical Foundations of Computer Networking, Addison-Wesley, 2012.

Any periodic signal is a sum of sinusoids

Let x(t) repeat every T0 seconds. Apart from some pathological signals, it can be written at nearly every t as

x(t) = a0 + ∞∑k=1 (ak cos kω0t + bk sin kω0t),   ω0 = 2πT0(EQ 5.29, 5.30)

The kth pair of terms has frequency kω0 and is called the kth harmonic. The constant a0 is a sinusoid of zero frequency, called the DC component. Once we know the coefficients, they specify the signal completely.

The coefficients are found by integrating over any one period:

a0 = 1T0T0∫0 x(t) dtak = 2T0T0∫0 x(t) cos kω0t dtbk = 2T0T0∫0 x(t) sin kω0t dt(EQ 5.31)

Each integral measures how much the signal looks like one particular sinusoid. Here T0 = 2 s, so ω0 = π rad/s. Choose a signal, then add harmonics one at a time and watch the sum close in on it. You can also draw your own period.

5
060

The sum with N harmonics

DC, a₀
—
largest value of the sum
—
RMS error over a period
—
highest frequency
—
x(t) and the sum of its first N harmonicsx(t), sum
The harmonics being addedeach ak cos kω0t + bk sin kω0t; the newest is highlighted
The coefficientsak and bk against k; the bar at k = 0 is a0
Python · EQ 5.31 and the partial sum

    

What to notice

A few harmonics already give the general shape. Smooth signals such as the triangle wave converge quickly, because their coefficients fall off like 1/k2. Signals with jumps, such as the square wave, converge slowly, because their coefficients fall off only like 1/k.

Near a jump the sum always overshoots. Adding harmonics squeezes the overshoot closer to the jump, but it does not make it smaller: the peak stays near 9% of the size of the jump. This is the Gibbs phenomenon of footnote 6. The RMS error still goes to zero, because the region where the overshoot lives becomes very narrow.

Symmetry decides which coefficients survive. An even signal, with x(−t) = x(t), needs only cosines; an odd one needs only sines. The shifted pulse is neither, so it needs both.

Try these

  1. Choose the square wave. Before looking at the table, decide which of ak and bk must be zero, and why the even harmonics are missing.
    Show answer
    The square wave here is odd, so every cosine coefficient ak and the mean a0 are zero. It also satisfies x(t + T0/2) = −x(t). An even harmonic is unchanged by a shift of half a period, so it cannot match a signal that changes sign under that shift. The integral for bk gives 4/(kπ) for odd k and 0 for even k: 1.2732, 0.4244, 0.2546, …
  2. With the square wave, read the largest value of the sum at N = 9, 19 and 49. Does adding harmonics remove the overshoot?
    Show answer
    No. The peak stays near 1.18 (1.1790 at N = 49) while the jump is from −1 to 1, so the overshoot is about 0.18, or 9% of the jump. The peak just moves closer to the jump. Meanwhile the RMS error keeps falling. This is why footnote 6 warns that the error near a jump does not go away, even with many tens of terms.
  3. Compare the square and triangle waves at N = 5. Which has the smaller RMS error, and how does the bar chart explain it?
    Show answer
    The triangle wave's error is far smaller. Its coefficients are 8/(kπ)2 for odd k, so the fifth harmonic is already 25 times smaller than the first. The square wave's coefficients fall only as 1/k, so the harmonics left out still carry a lot. In general, the smoother the signal, the faster its coefficients fall.
  4. Choose the shifted pulse (1 on 0 < t < 0.5). Predict a0, then explain why both ak and bk appear.
    Show answer
    a0 is the average value, 0.5/2 = 0.25. The pulse is neither even nor odd about t = 0, so it needs both cosines and sines. Each harmonic is then a single sinusoid with a phase shift, of amplitude √(ak2 + bk2). Compare with the centred pulse, which is even and has only cosine terms.