Chapter 22 — Exercises
Work the ⭐ and ⭐⭐ problems first; they build the muscle for the projection-in-function-space idea. The ⭐⭐⭐ problems split into proof (math majors) and coding (CS / data science / engineering) — do the track that fits your path, and the brave do both. ⭐⭐⭐⭐ problems are open-ended applications. Numerical answers should match
np.trapezoidto the decimals shown; keep the inner product $\langle f,g\rangle=\int_{-\pi}^{\pi} fg\,dx$ in front of you throughout.
⭐ Conceptual
22.1. In one sentence each, state what plays the role of (a) the vector, (b) the basis, (c) a coordinate, and (d) the dot product, when we do Fourier analysis as linear algebra.
22.2. True or false, with a reason: "Two functions are orthogonal when their graphs cross at a right angle." Give the correct definition of orthogonality for functions.
22.3. A signal is given as $g(x) = 2 - 5\cos 3x + \tfrac12\sin 8x$. Without integrating, write down every nonzero Fourier coefficient ($a_0$, the $a_k$, the $b_k$). Explain why no integration is needed.
22.4. Explain in your own words why the Fourier coefficients of a signal are independent of one another. What property of the basis makes this true, and what would go wrong without it?
22.5. The square wave's Fourier series contains only odd harmonics. Name the two symmetries responsible and say which one kills the cosines and which kills the even sines.
22.6. A friend says, "If I add enough sine terms, the Gibbs overshoot at the jump will shrink to zero." Correct them precisely: what does shrink, what does not, and in what sense the series still converges.
⭐⭐ Computation (by hand, then check with numpy)
22.7. Verify the orthogonality integral $\displaystyle\int_{-\pi}^{\pi}\cos 2x\,\cos 5x\,dx = 0$ by hand, using the product-to-sum identity $\cos A\cos B = \tfrac12[\cos(A-B)+\cos(A+B)]$.
22.8. Compute $\lVert \cos 4x\rVert^2 = \displaystyle\int_{-\pi}^{\pi}\cos^2 4x\,dx$ by hand (use $\cos^2\theta = \tfrac12(1+\cos 2\theta)$). Confirm it equals $\pi$.
22.9. Let $f(x) = x^2$ on $[-\pi,\pi]$ (an even function). Without computing them, explain which family of coefficients ($a_k$ or $b_k$) must all vanish, and why. Then set up — but you need not evaluate — the integral for $a_2$.
22.10. For the square wave, the Fourier series is $\tfrac{4}{\pi}\sum_{k\,\text{odd}}\tfrac{\sin kx}{k}$. Evaluate both sides at $x = \pi/2$ (where $f = +1$) to derive the famous identity $1 - \tfrac13 + \tfrac15 - \tfrac17 + \cdots = \tfrac{\pi}{4}$ (the Leibniz series). Show your steps.
22.11. Compute the first three nonzero Fourier coefficients of the sawtooth $f(x) = x$ on $(-\pi,\pi)$ by hand, using integration by parts on $\int x\sin kx\,dx$. Confirm they match $b_k = 2(-1)^{k+1}/k$, i.e. $b_1 = 2$, $b_2 = -1$, $b_3 = \tfrac23$.
22.12. A signal has Fourier coefficients $b_1 = 1$, $b_2 = \tfrac12$, all others zero (and all $a_k = 0$). Using Parseval's identity $\lVert f\rVert^2 = \pi\sum(a_k^2 + b_k^2)$, compute the signal's energy $\lVert f\rVert^2$.
22.13. Using the energy in Exercise 22.12, what fraction of the total energy is carried by the fundamental ($b_1$) alone? By both terms together (trivially)? State the answers as percentages.
⭐⭐⭐ Proof (A track)
22.14. Prove the orthogonality relation $\displaystyle\int_{-\pi}^{\pi}\sin kx\,\cos mx\,dx = 0$ for all positive integers $k, m$. (Hint: the integrand is an odd function of $x$; argue from symmetry, then optionally confirm with a product-to-sum identity.)
22.15. Prove that for any nonzero integer $n$, $\displaystyle\int_{-\pi}^{\pi}\cos(nx)\,dx = 0$ and $\displaystyle\int_{-\pi}^{\pi}\sin(nx)\,dx = 0$. State clearly where the hypothesis $n \neq 0$ is used.
22.16. Prove that the truncated Fourier series $S_N$ is the orthogonal projection of $f$ onto the subspace spanned by the first $N$ harmonics, and therefore the closest point to $f$ in that subspace under the norm $\lVert\cdot\rVert$. (Cite the closest-point theorem of Chapter 19 and the orthogonality relations of §22.3; you may assume the projection-onto-orthonormal-basis formula.)
22.17. Prove Parseval's identity for a finite trigonometric sum $f = a_0 + \sum_{k=1}^{N}(a_k\cos kx + b_k\sin kx)$: that $\lVert f\rVert^2 = 2\pi a_0^2 + \pi\sum_{k=1}^{N}(a_k^2 + b_k^2)$. (Expand $\langle f, f\rangle$ and use orthogonality to kill every cross term.) Identify exactly which step uses orthogonality.
22.18. Show that the complex exponentials $\{e^{ikx}\}_{k\in\mathbb{Z}}$ are orthogonal under the Hermitian inner product $\langle f,g\rangle = \int_{-\pi}^{\pi} f\overline{g}\,dx$, i.e. that $\int_{-\pi}^{\pi} e^{ikx}e^{-imx}\,dx$ equals $2\pi$ when $k=m$ and $0$ otherwise. State where you use that $k - m$ is a nonzero integer.
⭐⭐⭐ Coding (C track)
22.19. Implement fourier_coeffs(f, n) as described in the chapter's Build Your Toolkit callout: compute $a_0$, and the arrays of $a_k, b_k$ for $k = 1,\dots,n$, each by numerical projection with np.trapezoid on a fine grid over $[-\pi,\pi]$. Test it on f = lambda x: np.sign(np.sin(x)) with n=5 and confirm $b_1 \approx 1.2732$, $b_3 \approx 0.4244$, $b_5 \approx 0.2546$, and all $a_k \approx 0$.
22.20. Write reconstruct(a0, a, b, x) that evaluates the partial sum $a_0 + \sum_k(a_k\cos kx + b_k\sin kx)$ at an array of points x. Use it with the coefficients from Exercise 22.19 to plot $S_5$ over the square wave on $[-\pi,\pi]$. Visually identify the Gibbs overshoot.
22.21. Empirically measure the Gibbs peak. For $N = 5, 10, 50, 200$ odd-harmonic terms, compute the maximum of the partial sum on $(0,\pi)$ and print it. Confirm the values approach $\approx 1.179$ and do not approach $1.0$.
22.22. Compute the fraction of the square wave's energy captured by the first $N$ terms for $N = 1, 3, 5, 10, 50$ using Parseval (the chapter gives the formula). Confirm you get $81.06\%$, $93.31\%$, $95.96\%$, $97.98\%$, $99.60\%$. Then make a plot of "energy captured vs. number of terms."
22.23. Use np.fft.fft on $N = 2048$ samples of the square wave over one period to recover the coefficients, and compare $b_k = -2\,\mathrm{Im}(c_k)$ to $4/(\pi k)$ for $k = 1, 3, 5, 7$. Then increase $N$ to $16384$ and report how the agreement improves — explain the trend in terms of sampling error.
⭐⭐⭐⭐ Application
22.24. Triangle wave. The triangle wave (continuous, but with corners) has Fourier coefficients that decay like $1/k^2$, much faster than the square wave's $1/k$. (a) Numerically compute the first several coefficients of a triangle wave of your choice with fourier_coeffs. (b) Plot its partial sums and confirm there is no Gibbs overshoot. (c) Explain the connection: how does the smoothness of a signal (no jumps) relate to (i) the decay rate of its coefficients and (ii) the absence of Gibbs ringing? Tie your answer to the energy-capture idea — a faster-decaying spectrum means fewer terms suffice.
22.25. Build a one-knob equalizer. Take a synthetic signal that is a sum of three sines at frequencies $k = 1, 5, 20$ with equal amplitude. (a) Use fourier_coeffs to recover the three coefficients. (b) Write a function that reconstructs the signal but multiplies the high-frequency coefficient ($k = 20$) by a gain $g \in [0,1]$, then plot the result for $g = 1, 0.5, 0$. (c) In two or three sentences, connect what you did to the graphic equalizer described in §22.7: which projection are you scaling, and why does scaling one coefficient leave the others untouched? (d) Stretch: swap your synthetic signal for a short real audio clip loaded with a signals library and repeat — relate the result to the audio-compression case study.