CMP-272 · Lesson 6 of 12 · 23 min
Fourier series
The cheapest way to make a tone with a microcontroller is to toggle a pin: high for half a period, low for the other half. The result is a square wave, and when Amara first drives the accessible pedestrian signal's speaker amplifier that way, the 880 Hz locator tone sounds harsh and buzzy rather than clean. The reason is that a square wave is not one frequency. It is a sum of sinusoids at 880 Hz, 2,640 Hz, 4,400 Hz and every other odd multiple of 880 Hz, and the higher ones are what the ear hears as buzz. The Fourier series makes that statement exact. It writes any reasonable periodic signal as a sum of harmonically related sinusoids, tells you how strong each one is, and, combined with lesson 2's eigenfunction property, tells you what an LTI system does to each one.
Harmonics
A periodic signal with fundamental period T₀ has fundamental frequency f₀ = 1/T₀ and angular frequency ω₀ = 2π/T₀. Its harmonics are the frequencies kω₀ for integer k: the first harmonic is the fundamental, the second is 2ω₀, and so on. Any sinusoid at a harmonic frequency completes a whole number of cycles in T₀, so a sum of such sinusoids repeats with period T₀ as well. Fourier's claim, made in the early nineteenth century and made rigorous later, is that the converse is true: almost any periodic signal can be built as such a sum.
The exponential Fourier series
The neatest form uses complex exponentials. A periodic signal x(t) with period T₀ is written as
The integral runs over any one period. The coefficient c_k is a complex number whose magnitude is the strength of the kth harmonic and whose angle is its phase. The k = 0 coefficient, c₀, is the average value of the signal over a period, its DC component. The formula for c_k works because complex exponentials at different harmonics are orthogonal: the integral over one period of e^(jkω₀t)e^(−jmω₀t) is zero unless k = m. Multiplying the series by e^(−jmω₀t) and integrating therefore picks out a single coefficient, much as the sifting property picks out a single value.
For a real signal, the coefficients come in conjugate pairs, c_{−k} = c_k*, so the positive and negative harmonics combine into real sinusoids. The equivalent trigonometric form is
so the amplitude of the real sinusoid at harmonic k is 2|c_k|. Some textbooks write the series with separate cosine and sine coefficients a_k and b_k instead; they carry the same information, with a_k = 2 Re{c_k} and b_k = −2 Im{c_k}.
Symmetry saves work
Symmetry in the waveform shows up as structure in the coefficients. An even signal has only cosine terms, so its coefficients are real. An odd signal has only sine terms, so its coefficients are purely imaginary, and its DC value is zero. A signal with half-wave symmetry, x(t + T₀/2) = −x(t), meaning the second half of each period is the first half turned upside down, has only odd harmonics. A square wave with zero average has half-wave symmetry, which is why it contains 880 Hz, 2,640 Hz and 4,400 Hz but no 1,760 Hz.
Worked problem
Coefficients of a square wave
The pin output, after the speaker amplifier removes its DC level, is a square wave of amplitude A: x(t) = A for 0 < t < T₀/2 and −A for T₀/2 < t < T₀. Find c_k.
Show solution
- The average over a period is zero, so c₀ = 0. For k ≠ 0, split the integral into the two half periods, using ω₀T₀ = 2π.
- \[c_k = \frac{1}{T_0}\Big[\int_{0}^{T_0/2} A\,e^{-jk\omega_0 t}dt - \int_{T_0/2}^{T_0} A\,e^{-jk\omega_0 t}dt\Big] = \frac{A}{j2\pi k}\big(1 - e^{-jk\pi}\big)^2\]
- Since e^(−jkπ) = (−1)^k, the bracket is 0 for even k and 2 for odd k.
- \[c_k = \frac{A}{j2\pi k}\cdot 4 = \frac{2A}{j\pi k} \ \ (k \text{ odd}), \qquad c_k = 0 \ \ (k \text{ even})\]
- The amplitude of the real sinusoid at an odd harmonic is 2|c_k| = 4A/(πk).
Answer: x(t) = (4A/π)[sin(ω₀t) + (1/3)sin(3ω₀t) + (1/5)sin(5ω₀t) + …]. The fundamental's amplitude is 4A/π ≈ 1.27A, larger than the square wave itself, and the kth harmonic falls off as 1/k.
The line spectrum
Plotting |c_k| against frequency kf₀ gives the signal's line spectrum: a set of vertical lines at the harmonic frequencies, with heights equal to the harmonic strengths. Phase is plotted separately. The line spectrum is a second description of the same signal, in the frequency domain instead of the time domain, and many questions are easier there. How much of the buzz will a filter remove? Which harmonics fall inside the speaker's range? Will a harmonic land on a frequency that the noise detector is listening to? Each is answered by looking at the lines.
Pulse trains and duty cycle
Not every pin output has a 50 % duty cycle. A pulse train that is high for a time τ out of every period T₀ has duty cycle d = τ/T₀ and coefficients c_k = d·sin(πkd)/(πkd), measured from a pulse centered at t = 0. The DC value is c₀ = d, and the harmonic strengths follow an envelope that falls to zero wherever kd is a whole number. A 25 % duty cycle therefore has no fourth, eighth or twelfth harmonic but does have the second, sixth and tenth. As the pulses get narrower, the envelope widens and the harmonics stay strong to higher frequencies, which is why short, sharp pulses cause more radio interference than slow square waves. Lesson 7 shows that this envelope is the Fourier transform of a single pulse, sampled at the harmonic frequencies.
Power and Parseval's relation
The average power of a periodic signal can be computed in either domain. Parseval's relation says
Each harmonic contributes its own power, and the powers add because the harmonics are orthogonal. For the square wave, the time-domain power is simply A². The fundamental alone contributes 2|c₁|² = 8A²/π² ≈ 0.81A², so 81 % of the square wave's power is in the 880 Hz tone that Amara wants and 19 % is in the harmonics that make the buzz. The ratio of harmonic content to fundamental is called the total harmonic distortion, or THD:
For a square wave the THD is about 48 %, which is why it sounds so different from a sine.
Convergence and the Gibbs phenomenon
A Fourier series converges to the signal at every point where the signal is continuous, provided the signal satisfies mild conditions, known as the Dirichlet conditions, that every practical waveform meets: finite energy per period and finitely many jumps and wiggles. At a jump, the series converges to the midpoint of the jump. Near a jump, however, a partial sum with N harmonics always overshoots by about 9 % of the jump size, and adding more harmonics squeezes the overshoot closer to the edge without making it smaller. This is the Gibbs phenomenon. It appears whenever a signal with sharp edges is passed through a filter that cuts off its high harmonics abruptly, which is one reason filter designers sometimes prefer gentle cut-offs.
LTI systems and periodic inputs
Now combine the Fourier series with the eigenfunction property. Each harmonic e^(jkω₀t) passes through an LTI system as H(jkω₀)e^(jkω₀t), where H(jω) is the system's frequency response. By linearity, the response to the whole series is
So the output is periodic with the same period, and its Fourier coefficients are the input coefficients multiplied by the frequency response at each harmonic. A filter cannot create new harmonics; it can only make existing ones stronger or weaker and shift their phases. For the RC low-pass filter, lesson 8 shows that H(jω) = 1/(1 + jωRC). Amara adds a two-stage RC filter between the pin and the amplifier to soften the buzz.
Worked problem
Filtering the square wave
An RC filter with RC = 0.36 ms (corner frequency 1/(2πRC) ≈ 442 Hz) follows the 880 Hz square wave. By how much does it reduce the fundamental and the third harmonic?
Show solution
- The magnitude of the frequency response is 1/√(1 + (ωRC)²). At 880 Hz, ωRC = 2π(880)(0.36 × 10⁻³) ≈ 1.99.
- \[|H(j\omega_1)| = \frac{1}{\sqrt{1 + 1.99^2}} \approx 0.449\]
- At the third harmonic, 2,640 Hz, ωRC ≈ 5.97.
- \[|H(j3\omega_1)| = \frac{1}{\sqrt{1 + 5.97^2}} \approx 0.165\]
- The ratio of third harmonic to fundamental falls from 1/3 to (1/3)(0.165/0.449) ≈ 0.12.
Answer: The fundamental is cut to 45 % of its amplitude and the third harmonic to 17 %, so the third harmonic drops from 33 % to about 12 % of the fundamental. One RC stage helps but leaves audible buzz; Amara uses two stages and turns up the amplifier to make up the lost level.
import math
def square_partial(t, N, T0=1.0):
w0 = 2 * math.pi / T0
return sum(4 / (math.pi * k) * math.sin(k * w0 * t) for k in range(1, N + 1, 2))
for N in (5, 19, 99):
peak = max(square_partial(i / 20000, N) for i in range(2000)) # first tenth of a period
print(f"harmonics up to {N:3d}: peak = {peak:.4f} (overshoot {100*(peak-1)/2:.1f} % of the jump)")
P_total = 1.0 # square wave of amplitude 1
for N in (1, 3, 9, 49):
P = sum(0.5 * (4 / (math.pi * k)) ** 2 for k in range(1, N + 1, 2))
print(f"power in harmonics up to {N:2d}: {100*P/P_total:.1f} %")
f0, RC, stages = 880.0, 0.36e-3, 2
def amp(k):
H = 1 / math.sqrt(1 + (2 * math.pi * k * f0 * RC) ** 2)
return 4 / (math.pi * k) * H ** stages
harm = math.sqrt(sum(amp(k) ** 2 for k in range(3, 400, 2)))
print(f"THD of raw square wave: {100*math.sqrt(1 - 8/math.pi**2)/math.sqrt(8/math.pi**2):.1f} %")
print(f"THD after {stages} RC stages: {100*harm/amp(1):.1f} %")harmonics up to 5: peak = 1.1884 (overshoot 9.4 % of the jump) harmonics up to 19: peak = 1.1798 (overshoot 9.0 % of the jump) harmonics up to 99: peak = 1.1790 (overshoot 9.0 % of the jump) power in harmonics up to 1: 81.1 % power in harmonics up to 3: 90.1 % power in harmonics up to 9: 96.0 % power in harmonics up to 49: 99.2 % THD of raw square wave: 48.3 % THD after 2 RC stages: 4.6 %
The overshoot stays near 9 % of the jump however many harmonics are added. Half of the 2 units of jump is 1, so a peak of about 1.18 means 0.18 above the top, or 9 % of the full jump. The power table shows the fundamental alone carrying about 81 % of the power and the first five odd harmonics about 96 %. The last two lines show why Amara's two RC stages work: the THD falls from about 48 % to under 5 %, close to a clean tone, because each stage hits the higher harmonics harder than the fundamental.
Common mistakes
MistakeForgetting the factor of 2 when converting c_k to a real amplitude.
InsteadA real sinusoid needs both c_k and c_{−k}; its amplitude is 2|c_k|.
MistakeExpecting even harmonics in a symmetric square wave.
InsteadHalf-wave symmetry removes all even harmonics; a square wave with a duty cycle other than 50 % does have them.
MistakeThinking more harmonics will remove the Gibbs overshoot.
InsteadThe overshoot narrows but stays at about 9 % of the jump for any finite number of harmonics.
MistakeApplying H(jω) at the wrong frequency.
InsteadEach harmonic is scaled by H evaluated at its own frequency kω₀, not at the fundamental.
MistakeUsing Parseval's relation with real amplitudes and forgetting the ½.
InsteadA real sinusoid of amplitude a has power a²/2, which equals 2|c_k|² for the pair of coefficients.
Summary and key terms
- A periodic signal is a sum of complex exponentials at harmonics of its fundamental frequency, with coefficients c_k = (1/T₀)∫x(t)e^(−jkω₀t)dt.
- For real signals c_{−k} = c_k*, and the real amplitude at harmonic k is 2|c_k|; c₀ is the average value.
- Even signals have cosine terms, odd signals sine terms, and half-wave-symmetric signals only odd harmonics.
- Parseval's relation adds harmonic powers to give the total power; THD compares harmonic power with the fundamental.
- Partial sums overshoot by about 9 % near jumps, the Gibbs phenomenon.
- An LTI system multiplies each harmonic coefficient by H(jkω₀); it cannot create new harmonics.
- Fourier series
- The representation of a periodic signal as a sum of harmonically related complex exponentials or sinusoids.
- Harmonic
- A frequency that is an integer multiple of the fundamental frequency.
- Line spectrum
- A plot of Fourier coefficient magnitudes against frequency for a periodic signal.
- Parseval's relation
- The statement that average power equals the sum of the squared magnitudes of the Fourier coefficients.
- Total harmonic distortion
- The ratio of the RMS of all harmonics above the fundamental to the fundamental.
- Gibbs phenomenon
- The persistent overshoot of about 9 % near a jump in a truncated Fourier series.
- Half-wave symmetry
- The property x(t + T₀/2) = −x(t), which removes even harmonics.
Practice problems
Work each problem on paper first, then reveal the answer to check.
What is c₀ for a square wave that switches between 0 and 3.3 V with a 50 % duty cycle?
Show answer
The average, 1.65 V.
Find the Fourier series of x(t) = 3 + 2cos(100πt) − sin(300πt).
Show answer
c₀ = 3, c_{±1} = 1, c_{±3} = ±j/2 (with ω₀ = 100π); c₃ = j/2 and c₋₃ = −j/2.
A triangle wave's harmonics fall off as 1/k². Why does it sound softer than a square wave?
Show answer
Its upper harmonics are much weaker, so its THD is only about 12 %.
Which harmonics does a 25 % duty cycle pulse train contain?
Show answer
All except multiples of 4; it has no half-wave symmetry, so even harmonics such as the second are present.
A square wave of amplitude 2 V drives a 1 Ω load. How much power is in the fundamental?
Show answer
(4·2/π)²/2 ≈ 3.24 W out of 4 W total.
An LTI system has H(j2π·880) = 0.5∠−60°. What is its output for cos(2π·880t)?
Show answer
0.5cos(2π·880t − 60°).
Lesson quiz · 5 questions
Score 60% or more to complete this lesson.
Create a free account to save your progress, take quizzes and earn a certificate.