Fourier coefficients by integration
Tonight's idea
The harmonics sheet said a repeating signal is a sum of sines and cosines. Tonight we compute the amounts. Take the square wave of period \(2\pi\): \(f(x) = 1\) for \(0 \lt x \lt \pi\) and \(-1\) for \(-\pi \lt x \lt 0\). It is odd, so only sines can appear. Suppose \(f(x) = \sum_{k \ge 1} b_k \sin kx\), where \(b_k\) is the amplitude of the \(k\)-th harmonic.
The key is orthogonality. From \(\sin A\sin B = \tfrac12[\cos(A-B) - \cos(A+B)]\), for whole numbers \(m \ne k\),
\[\int_{-\pi}^{\pi}\sin mx\,\sin kx\,dx = 0, \qquad \int_{-\pi}^{\pi}\sin^2 kx\,dx = \pi.\]
Multiply the series by \(\sin kx\) and integrate over one period. Every term dies except the \(k\)-th, which leaves \(\pi b_k\), so
\(b_k = \dfrac1\pi\displaystyle\int_{-\pi}^{\pi} f(x)\sin kx\,dx.\)
Each coefficient is fished out by its own sine. For the square wave, \(f(x)\sin kx\) is even, so
\[b_k = \frac2\pi\int_0^{\pi}\sin kx\,dx = \frac2\pi\Big[-\frac{\cos kx}{k}\Big]_0^{\pi} = \frac{2(1 - \cos k\pi)}{k\pi},\]
which is \(4/(k\pi)\) for odd \(k\) and \(0\) for even \(k\). Only odd harmonics, decaying like \(1/k\): the clarinet's hollow sound from the harmonics sheet.
Watch one: \(x = \pi/2\), and the overshoot
At \(x = \pi/2\) every sine is \(\pm 1\), so \(1 = \tfrac4\pi\big(1 - \tfrac13 + \tfrac15 - \cdots\big)\): Leibniz's series for \(\pi/4\), for free. Three terms give \(1.1035\), not yet close.
Near the jump something odder happens. However many terms you take, the first ripple beside \(x = 0\) peaks at about \(1.18\): an overshoot of \(0.18\), about 9% of the jump of 2. It gets narrower but never shorter: the Gibbs phenomenon.
Slide the number of harmonics and watch the ripple squeeze toward the jump: mathdetours.com/demos/squarewave.html. Hear the harmonics at mathdetours.com/demos/fourier.html.
Your turn
- Compute \(\int_0^{\pi}\sin 2x\,dx\) and \(\int_0^{\pi}\sin 3x\,dx\) directly, and confirm \(b_2 = 0\) and \(b_3 = 4/(3\pi)\).
- (a) Use the product-to-sum identity to compute \(\int_{-\pi}^{\pi}\sin x\sin 2x\,dx\). (b) Explain in one sentence why \(\int_{-\pi}^{\pi} f(x)\cos kx\,dx = 0\) for the square wave, so that no cosines appear.
- The sawtooth: \(f(x) = x\) on \(-\pi \lt x \lt \pi\), repeated. Use integration by parts to find \(b_k\), and write out the first three terms of the series.
- Square both sides of the square-wave series and integrate from \(-\pi\) to \(\pi\). (a) Explain why the cross terms vanish, and deduce \(\dfrac1\pi\displaystyle\int_{-\pi}^{\pi} f(x)^2\,dx = \sum b_k^2\). (b) Evaluate both sides to show \(1 + \tfrac19 + \tfrac1{25} + \cdots = \tfrac{\pi^2}{8}\). (c) Deduce \(\sum_{k\ge1} 1/k^2 = \pi^2/6\).
Stretch: where 1.18 comes from
Let \(S_m(x)\) be the sum of the first \(m\) odd harmonics. Given \(\sum_{j=0}^{m-1}\cos(2j+1)x = \frac{\sin 2mx}{2\sin x}\), find \(S_m'(x)\), locate the first peak, and show that as \(m \to \infty\) its height tends to \(\frac2\pi\int_0^{\pi}\frac{\sin u}{u}\,du \approx 1.179\).
Answers
- \(\big[-\tfrac{\cos 2x}{2}\big]_0^{\pi} = -\tfrac12 + \tfrac12 = 0\), so \(b_2 = 0\). \(\big[-\tfrac{\cos 3x}{3}\big]_0^{\pi} = \tfrac13 + \tfrac13 = \tfrac23\), so \(b_3 = \tfrac2\pi \cdot \tfrac23 = \tfrac{4}{3\pi}\).
- (a) \(\sin x\sin 2x = \tfrac12(\cos x - \cos 3x)\), and \(\int_{-\pi}^{\pi}\cos x\,dx = \int_{-\pi}^{\pi}\cos 3x\,dx = 0\), so the integral is 0. (b) \(f\) is odd and \(\cos kx\) is even, so the product is odd and its integral over a symmetric interval is zero.
- \(b_k = \tfrac1\pi\int_{-\pi}^{\pi} x\sin kx\,dx\). Parts with \(u = x\), \(dv = \sin kx\,dx\): \(\Big[-\tfrac{x\cos kx}{k}\Big]_{-\pi}^{\pi} + \tfrac1k\int_{-\pi}^{\pi}\cos kx\,dx = -\tfrac{2\pi\cos k\pi}{k} + 0\). So \(b_k = \tfrac{2(-1)^{k+1}}{k}\): \(f(x) = 2\sin x - \sin 2x + \tfrac23\sin 3x - \cdots\). All harmonics this time, decaying like \(1/k\) again because of the jump at \(\pm\pi\).
- (a) Squaring gives \(\sum b_k^2\sin^2 kx\) plus cross terms \(b_m b_k \sin mx\sin kx\) with \(m \ne k\), which integrate to zero by orthogonality; each \(\sin^2 kx\) integrates to \(\pi\). (b) \(f^2 = 1\), so the left side is \(2\). The right side is \(\tfrac{16}{\pi^2}\big(1 + \tfrac19 + \tfrac1{25} + \cdots\big)\), hence the odd sum is \(\tfrac{2\pi^2}{16} = \tfrac{\pi^2}{8}\). (c) Let \(S = \sum 1/k^2\). The even terms are \(\sum 1/(2j)^2 = S/4\), so \(S - S/4 = \pi^2/8\) and \(S = \pi^2/6\): the Basel sum.
Stretch. \(S_m'(x) = \tfrac4\pi\sum\cos(2j+1)x = \tfrac2\pi\,\dfrac{\sin 2mx}{\sin x}\), first zero at \(x = \pi/(2m)\), the first peak. Its height is \(\int_0^{\pi/2m} S_m'\,dx\). Substitute \(u = 2mx\); for large \(m\), \(x\) is tiny and \(\sin x \approx x = u/2m\), so the integral becomes \(\tfrac2\pi\int_0^{\pi}\tfrac{\sin u}{u}\,du = 1.179\). The peak slides toward the jump as \(1/m\) but its height does not move.