Flow Lab

Syllabus / Module 8: Boundary Value Problems & Fourier Series

Lesson 8.5

Convergence & the Gibbs Phenomenon

Pointwise, uniform and mean-square convergence; decay of coefficients vs smoothness; Gibbs overshoot; DFT/FFT bridge.

Written byClaude Sonnet

🌊
Why this matters for simulation: Gibbs-like overshoots at shocks plague high-order fluid solvers; limiters exist to tame them.

By the end of this lesson you can…

  • Distinguish mean-square, pointwise and uniform convergence, and say which holds for a square wave, a triangle wave and a smooth function.
  • State the Dirichlet theorem and use it to find the value the series takes at a jump.
  • Derive the Gibbs overshoot, $\tfrac{2}{\pi}\mathrm{Si}(\pi) = 1.1790$ for a jump from $-1$ to $+1$, and explain why it narrows but does not shrink.
  • Build Fejér, Lanczos, raised-cosine and exponential filters from sigma factors and predict how each trades ringing for sharpness.
  • Predict the rate at which the error falls from the smoothness of $f$, and read it off a log-log plot.
  • Describe the discrete Fourier transform as a quadrature rule, explain aliasing, and say why the FFT costs $M\log_2 M$ operations.
On this page
·
  1. Three meanings of “converges”
  2. The Dirichlet theorem and the midpoint
  3. The Gibbs overshoot, derived
  4. Cure one: average away the ringing (Fejér)
  5. Cure two: a moving average (Lanczos), and other sigma factors
  6. Convergence rate against smoothness
  7. Worked example: the Fejér mean by hand
  8. From series to samples: the DFT and the FFT
  9. Computing it
  10. Concept checks
  11. Problems
  12. Key Takeaways
  13. What comes next

8.3 Fourier Series ended with a loose thread. We wrote f=∑(akcos⁡kx+bksin⁡kx)f = \sum (a_k\cos kx + b_k\sin kx) and checked it numerically, but the square wave’s partial sums kept an overshoot: max⁡SN=1.2732, 1.2004, 1.1884\max S_N = 1.2732,\ 1.2004,\ 1.1884 at N=1,3,5N = 1, 3, 5, and still about 1.1791.179 at N=39N = 39. This lesson says what "==" means in that formula, why the overshoot cannot be removed by adding terms, and what to do about it. A spectral fluid solver stores each field as a truncated series, and the series next to a sharp front is the one studied here. 10.10 The Finite Volume Method ended with a related symptom in a different scheme; we will be careful about how far the relationship goes.

▶ Video Partial sums of the square wave: the bump next to the jump gets narrower, never smaller; then filters smooth it awaycaptions only
Transcript
  1. Last time the square wave's partial sums kept an overshoot. So what does the equals sign mean? Three things. Mean-square: the root mean square error goes to zero for every finite-energy function, jumps included. Pointwise: the sum approaches a number at each x separately. Uniform: the worst error over all x goes to zero. A jump rules that out, because every partial sum is continuous. Even the mean-square rate is slow: about 2 over pi root N plus 1, 0.1006 at 39 terms, 0.0563 at 127.
  2. Look next to the jump. The one-term sum peaks at 1.2732, three terms 1.2004, five terms 1.1884. At 39 terms the peak is 1.17919, at 127 terms 1.17901. As a share of the jump, which has size 2, that is 13.66 percent, 10.02, 9.42, 8.96, and 8.95. The peaks fall quickly, then stall.
  3. Why 1.179? Differentiate the sum: 2 over pi times sine of N plus 1 times x, over sine x. It first vanishes at x equals pi over N plus 1, the peak. The height is 2 over pi times the integral of sine s over s from 0 to pi, which is Si of pi. That is 1.851937, so the limit is 1.17898: an overshoot of 8.95 percent of the jump. At 5 terms, by hand, 1.18836.
  4. Why does it narrow but not shrink? The bump is one fixed shape, squeezed horizontally by the factor N plus 1. Its peak sits at pi over N plus 1: 0.07854 at 39 terms, 0.02454 at 127. At any fixed x above zero the bump passes by and the sum tends to 1. But at the moving peak the error is always 0.179: uniform convergence fails, drawn as a picture. It is no numerical artifact; it is what finitely many smooth waves do to a step.
  5. Two cures. Fejér averages the first N plus 1 partial sums, multiplying each term by 1 minus k over N plus 1. Its kernel is never negative, so it cannot overshoot: the maximum is 0.84883 at 3 terms, 0.98409 at 39, 0.99503 at 127. Lanczos averages over a window as wide as the bump, a sinc factor. That leaves a 1.19 percent overshoot, maximum 1.0237.
  6. How fast does the error fall? A jump in the m-th derivative gives rms error falling like N to the minus m plus a half: a straight line on a log-log plot. The square wave measures minus 0.487, the triangle minus 1.461, and the quartic, whose third derivative jumps, minus 3.453. A smooth function like exp of cosine x beats every power: a factor of 100 per two modes, 3.9 times 10 to the minus 3 at 3 terms, 3.2 times 10 to the minus 5 at 5.
  7. Now the exponential filter of spectral codes, with exponent p. A high order leaves most modes alone. At p equals 8 it keeps the front sharp and most of the ringing, 7.82 percent, while the error away from the jump falls to 3.7 times 10 to the minus 6. At p equals 2 the ringing is gone, the maximum is exactly 1.0000, but the front is smeared and the rms error is 0.1410. The plain sum has the smallest rms error, 0.0563: the ringing is the price of that optimality.
  8. Computers sample. With M points and the trapezoid rule, the coefficients become the discrete Fourier transform, an orthogonal change of basis. The catch is aliasing: on the grid, mode k and mode k plus M are the same samples, so modes beyond the Nyquist limit land on slower ones. A jump leaks about 1 over M into every retained mode. The direct sum costs M squared; splitting into even and odd samples gives the fast Fourier transform, M log 2 M. For M equal to 1024, roughly 100 times fewer steps.
  9. Spectral fluid solvers live on these facts. They use the FFT on a periodic box. A product of two fields creates modes up to twice the highest retained, so the 2 thirds rule zeroes the top third after each product. A shock rings, so codes filter every step or add viscosity, and the linear filter smears smooth regions too. The ringing resembles Lax-Wendroff's, 1.2129 and minus 0.2074 on a pulse of height 1, but not in mechanism: that is a dispersion error building up over time steps, while Gibbs sits in a frozen snapshot.
  10. To recap. Mean-square convergence always holds, pointwise gives the midpoint at a jump, uniform fails. The Gibbs bump rises to 1.17898, 8.95 percent of the jump, and narrows without shrinking. Smoothness sets the rate. Fejér is monotone but first order; high-order filters keep most of the ringing. Next, special functions: a pipe or a sphere gives Bessel functions and Legendre polynomials, and we ask which of these rules survive.

Three meanings of “converges”

A series SN(x)→f(x)S_N(x) \to f(x) can fail or succeed in three different ways.

Mean-square (L2) convergence means ∥f−SN∥rms→0\|f - S_N\|_{\text{rms}} \to 0, where the root-mean-square error is the square root of the average of (f−SN)2(f - S_N)^2 over a period. By Parseval (8.3 Fourier Series) the energy missed by SNS_N is the tail of the coefficient sum, which goes to zero for every ff of finite energy, jumps included (completeness of sines and cosines; from memory). For the square wave the tail is 8π2∑k odd > Nk−2\tfrac{8}{\pi^2}\sum_{k\text{ odd}\,\gt\,N}k^{-2}, which an integral comparison (Calc II) approximates by 4π2(N+1)\tfrac{4}{\pi^2(N+1)}, so

rms error of SN≈2πN+1.\text{rms error of } S_N \approx \frac{2}{\pi\sqrt{N+1}} .

At N=39N = 39 this gives 0.10070.1007 (the sim reads 0.10060.1006) and at N=127N = 127 it gives 0.05630.0563 (the sim reads 0.05630.0563): the error goes to zero, but only like N−1/2N^{-1/2}.

Pointwise convergence means SN(x)→S_N(x) \to a number, at each xx separately. Uniform convergence means the worst error over all xx goes to zero. Uniform implies pointwise, not the reverse. A Calc II fact decides the matter: a uniform limit of continuous functions is continuous. Every partial sum is continuous, so the series of a function with a jump cannot converge uniformly. Conversely, if ∑(∣ak∣+∣bk∣)\sum(|a_k| + |b_k|) is finite, the Weierstrass MM-test gives uniform convergence: the triangle wave has ∣ak∣=4/(πk2)|a_k| = 4/(\pi k^2), summable, so it converges uniformly; the square wave has 4/(πk)4/(\pi k), which is not.

The Dirichlet theorem and the midpoint

What does the series do at a single point? Insert ck=12π∫f(t)e−iktdtc_k = \frac1{2\pi}\int f(t)e^{-ikt}dt into SN(x)=∑k=−NNckeikxS_N(x) = \sum_{k=-N}^N c_k e^{ikx} and sum the geometric series inside the integral:

SN(x)=12π∫−ππf(t) DN(x−t) dt,DN(s)=∑k=−NNeiks=sin⁡((N+12)s)sin⁡(s/2).S_N(x) = \frac1{2\pi}\int_{-\pi}^{\pi} f(t)\,D_N(x - t)\,dt,\qquad D_N(s) = \sum_{k=-N}^{N}e^{iks} = \frac{\sin\bigl((N + \tfrac12)s\bigr)}{\sin(s/2)} .

The partial sum is ff averaged against the Dirichlet kernel DND_N: a spike of height 2N+12N + 1 at s=0s = 0 with total weight 2π2\pi, surrounded by sign-changing ripples. The ripples are the story of this lesson.

Dirichlet’s theorem (from memory, not proved here): if ff and f′f' are piecewise continuous, then SN(x)→12[f(x+)+f(x−)]S_N(x) \to \tfrac12\bigl[f(x^+) + f(x^-)\bigr] at every xx. At a point where ff is continuous this is f(x)f(x). At a jump it is the midpoint of the two sides. For the square wave at x=0x = 0 the midpoint is 00, and every term sin⁡kx\sin kx vanishes there, so the sim reads SN(0)=0.000000S_N(0) = 0.000000 for every NN; for the sawtooth at its jump x=πx = \pi it also reads 00, the average of ±π\pm\pi.

Away from the jump convergence is slow but sure. At x=π/2x = \pi/2 the square-wave sum is the Leibniz series 4π(1−13+15−⋯ )\tfrac4\pi(1 - \tfrac13 + \tfrac15 - \cdots), whose error is about half the first omitted term, 2π(N+1)\tfrac{2}{\pi(N+1)}. The sim gives S1,S3,S5=1.2732, 0.8488, 1.1035S_1, S_3, S_5 = 1.2732,\ 0.8488,\ 1.1035, and then 0.98410.9841 at N=39N = 39 and 0.99500.9950 at N=127N = 127, errors of 0.01590.0159 and 0.00500.0050, matching 2/(40π)=0.01592/(40\pi) = 0.0159 and 2/(128π)=0.00502/(128\pi) = 0.0050.

The Gibbs overshoot, derived

Why does the maximum stay near 1.181.18? Differentiate the square-wave sum, for odd NN:

SN′(x)=4π∑k odd≤Ncos⁡kx=2π sin⁡((N+1)x)sin⁡x.S_N'(x) = \frac4\pi\sum_{k\text{ odd}\le N}\cos kx = \frac{2}{\pi}\,\frac{\sin\bigl((N+1)x\bigr)}{\sin x}.

This vanishes first at xN=π/(N+1)x_N = \pi/(N+1), so the first maximum of SNS_N sits there, and

SN(xN)=2π∫0π/(N+1)sin⁡((N+1)t)sin⁡t dt  ⟶  2π∫0πsin⁡ss ds=2π Si(π)(N→∞),S_N(x_N) = \frac2\pi\int_0^{\pi/(N+1)}\frac{\sin\bigl((N+1)t\bigr)}{\sin t}\,dt \;\longrightarrow\; \frac2\pi\int_0^{\pi}\frac{\sin s}{s}\,ds = \frac2\pi\,\mathrm{Si}(\pi)\quad (N \to \infty),

using s=(N+1)ts = (N+1)t and sin⁡t≈t\sin t \approx t for small tt. Since Si(π)=1.851937\mathrm{Si}(\pi) = 1.851937, the limit is 1.178981.17898. The bump rises 0.178980.17898 above 11: an overshoot of about 8.95%8.95\% of the jump of size 22.

The sim’s maxima of SNS_N at N=1,3,5,39,127N = 1, 3, 5, 39, 127 are 1.27324, 1.20042, 1.18836, 1.17919, 1.179011.27324,\ 1.20042,\ 1.18836,\ 1.17919,\ 1.17901, which as percentages of the jump are 13.66%, 10.02%, 9.42%, 8.96%, 8.95%13.66\%,\ 10.02\%,\ 9.42\%,\ 8.96\%,\ 8.95\%. The peak sits at π/(N+1)\pi/(N+1): 0.078540.07854 for N=39N = 39 and 0.024540.02454 for N=127N = 127. By hand at N=5N = 5, peak at π/6\pi/6: S5(π/6)=4π(12+13+110)=1.18836S_5(\pi/6) = \tfrac4\pi(\tfrac12 + \tfrac13 + \tfrac1{10}) = 1.18836, the sim’s value.

◆ Interactive Choose a function, a filter and N; compare the sum, the overshoot against N, and the log-log error

Loading simulation…

What to try. (1) Square wave, no filter, zoom on, N=9,39,127N = 9, 39, 127. (2) The sawtooth: the same percentage of its jump 2π2\pi, approached slowly (7.69%7.69\% at N=39N = 39, 8.56%8.56\% at N=127N = 127) because ff is still rising under the bump. (3) Each filter. (4) Triangle and quartic: the slope of the rms line.

Why it narrows but does not shrink. The bump is a fixed shape squeezed horizontally by the factor N+1N + 1. At any fixed x>0x \gt 0 it eventually passes by and SN(x)→1S_N(x) \to 1 (pointwise convergence), but at π/(N+1)\pi/(N+1) the error is always 0.1790.179: the failure of uniform convergence, with a picture. The overshoot belongs to the representation, not to any numerical method: it is what approximating a step by a finite number of smooth waves does. It occurs, with the same 8.95%8.95\%, at every jump of every piecewise smooth function (from memory; the sim checks the square wave and, with a slope correction, the sawtooth).

Cure one: average away the ringing (Fejér)

Average the ripples of DND_N away. The Cesàro (Fejér) mean is the average of the first N+1N + 1 partial sums,

σN(x)=1N+1∑n=0NSn(x).\sigma_N(x) = \frac1{N+1}\sum_{n=0}^{N}S_n(x).

The term of frequency kk appears in SnS_n for all n≥kn \ge k, i.e. in N+1−kN + 1 - k of the N+1N + 1 sums, so the mean is the ordinary partial sum with each term multiplied by a sigma factor

σk=1−kN+1.\sigma_k = 1 - \frac{k}{N+1}.

Averaging the kernels likewise gives the Fejér kernel KN(s)=1N+1(sin⁡(N+1)s2/sin⁡s2)2K_N(s) = \tfrac{1}{N+1}\bigl(\sin\tfrac{(N+1)s}{2}/\sin\tfrac s2\bigr)^2, which is never negative and has the same total weight 2π2\pi as DND_N (from memory). A positively weighted average of values of ff lies between the smallest and largest of them: no overshoot is possible. The sim agrees: for the square wave the Fejér sum peaks at 0.848830.84883 for N=3N = 3, 0.984090.98409 for N=39N = 39 and 0.995030.99503 for N=127N = 127, always under 11. For continuous ff it converges uniformly (Fejér’s theorem; from memory).

Cure two: a moving average (Lanczos), and other sigma factors

The Gibbs bump has width π/(N+1)\pi/(N+1), so average SNS_N over a window of half-width h=π/(N+1)h = \pi/(N+1). Calc II gives 12h∫x−hx+hsin⁡kt dt=sin⁡kx⋅sin⁡khkh\frac1{2h}\int_{x-h}^{x+h}\sin kt\,dt = \sin kx\cdot\frac{\sin kh}{kh}, so the windowed average is again the partial sum with

σk=sin⁡(πk/(N+1))πk/(N+1).\sigma_k = \frac{\sin\bigl(\pi k/(N+1)\bigr)}{\pi k/(N+1)}.

This is the Lanczos sigma factor. Two others: the raised cosine σk=12(1+cos⁡πkN+1)\sigma_k = \tfrac12\bigl(1 + \cos\tfrac{\pi k}{N+1}\bigr) and the exponential filter σk=exp⁡(−36(k/N)p)\sigma_k = \exp\bigl(-36(k/N)^p\bigr) of even order pp, used in spectral codes (36≈−ln⁡10−1636 \approx -\ln 10^{-16} makes the last mode round-off small; from memory). Each is a one-line change.

At N=127N = 127 on the square wave the sim gives:

filtermax of sumovershootrms errorworst error at least 0.50.5 from a jump
none1.17901.17908.950%8.950\%0.05630.05631.0×10−21.0\times10^{-2}
Fejér0.99500.9950none0.07960.07961.05×10−21.05\times10^{-2}
Lanczos1.02371.02371.187%1.187\%0.06920.06921.5×10−41.5\times10^{-4}
raised cosine1.01271.01270.635%0.635\%0.07540.07541.1×10−51.1\times10^{-5}
exponential, p=8p = 81.15641.15647.821%7.821\%0.07040.07043.7×10−63.7\times10^{-6}
exponential, p=2p = 21.00001.0000none0.14100.1410below 10−1310^{-13}

Three lessons sit in this table. First, the plain sum has the smallest rms error: it is the orthogonal projection of ff onto the first NN modes (1.1 Vectors, Linear Combinations & Span), and any filter moves away from it. The ringing is the price of that optimality. Second, all but Fejér buy accuracy away from the jump: the worst error at least 0.50.5 from every jump is 10−210^{-2} plain but 10−410^{-4} to 10−610^{-6} filtered. Third, the order-88 exponential filter leaves most modes alone and keeps the front sharp, and with it most of the ringing (7.82%7.82\%); the order-22 version kills the ringing by smearing the front.

Convergence rate against smoothness

The previous lessons said a jump in the mm-th derivative gives coefficients of size k−(m+1)k^{-(m+1)}. The tail energy ∑k>Nk−2(m+1)\sum_{k\gt N}k^{-2(m+1)} is about N−(2m+1)N^{-(2m+1)} (integral comparison), so the rms error falls like N−(m+1/2)N^{-(m + 1/2)}. The sim fits the slope of log⁡10rms\log_{10}\text{rms} against log⁡10N\log_{10}N over N=15N = 15 to 127127:

functionjump inpredicted slopemeasured
square waveff (m=0m = 0)−0.5-0.5−0.487-0.487
triangle ∣x∣\lvert x\rvertf′f' (m=1m = 1)−1.5-1.5−1.461-1.461
quartic (1−x2/π2)2(1 - x^2/\pi^2)^2f′′′f''' (m=3m = 3)−3.5-3.5−3.453-3.453
exp⁡(cos⁡x)\exp(\cos x)nonefaster than any powerrms 3.9×10−33.9\times10^{-3} at N=3N = 3, 3.2×10−53.2\times10^{-5} at N=5N = 5

For the smooth function the error drops by about a factor 100100 per two extra modes: this spectral (faster than any power) convergence is what spectral methods exploit. At N=39N = 39 the worst error is 3.0×10−23.0\times10^{-2} for the square wave and 2.7×10−62.7\times10^{-6} for the quartic.

Now the filters again. A smooth ff keeps an error of about ∑(1−σk)ckeikx\sum(1 - \sigma_k)c_ke^{ikx}. For Fejér, 1−σk=k/(N+1)1 - \sigma_k = k/(N+1) is of order 1/N1/N even for k=1k = 1, so the error cannot beat 1/N1/N however smooth ff is: the measured slope is −0.97-0.97 for the triangle, the quartic and exp⁡(cos⁡x)\exp(\cos x) alike. For Lanczos and the raised cosine, 1−σk≈const⋅(k/N)21 - \sigma_k \approx \text{const}\cdot(k/N)^2, so the best slope is −2-2 (measured −1.95-1.95 on the quartic and on exp⁡(cos⁡x)\exp(\cos x)). For the order-8 exponential the best is −8-8: the sim measures −7.999-7.999 on exp⁡(cos⁡x)\exp(\cos x) and keeps the full rates −1.50-1.50 and −3.50-3.50 on the triangle and quartic. The filter’s order is the order at which 1−σk1 - \sigma_k vanishes at k=0k = 0.

Worked example: the Fejér mean by hand

At N=3N = 3 the sigma factors are σ1=34\sigma_1 = \tfrac34 and σ3=14\sigma_3 = \tfrac14 (the even terms are zero). At x=π/2x = \pi/2, sin⁡π2=1\sin\tfrac\pi2 = 1 and sin⁡3π2=−1\sin\tfrac{3\pi}2 = -1, so the Fejér sum is 4π(34−14⋅13)=4π⋅23=0.84883\tfrac4\pi\bigl(\tfrac34 - \tfrac14\cdot\tfrac13\bigr) = \tfrac4\pi\cdot\tfrac23 = 0.84883, which the sim reports as the maximum of the Fejér sum at N=3N = 3. (By coincidence the plain S3(π/2)=4π(1−13)S_3(\pi/2) = \tfrac4\pi(1 - \tfrac13) has the same value.)

From series to samples: the DFT and the FFT

A simulation samples ff at MM equally spaced points xj=2πj/Mx_j = 2\pi j/M and applies the trapezoid rule (2.5 Multiple Integrals) to ck=12π∫fe−ikxdxc_k = \frac{1}{2\pi}\int f e^{-ikx}dx. The result is the discrete Fourier transform

c^k=1M∑j=0M−1f(xj) e−2πijk/M,k=0,…,M−1.\hat c_k = \frac1M\sum_{j=0}^{M-1}f(x_j)\,e^{-2\pi i jk/M},\qquad k = 0, \dots, M-1 .

It is a change of orthogonal basis: ∑je2πij(k−l)/M\sum_j e^{2\pi ij(k-l)/M} is MM if k−lk - l is a multiple of MM and 00 otherwise (a geometric sum). The same sum shows the catch: on the grid eikxe^{ikx} and ei(k+M)xe^{i(k+M)x} are the same samples, so c^k=∑mck+mM\hat c_k = \sum_m c_{k+mM} and every mode beyond ∣k∣≈M/2\lvert k\rvert \approx M/2 (the Nyquist limit) is aliased onto a slower one. A smooth spectrum loses little; a jump, with ck∼1/kc_k\sim1/k, leaks about 1/M1/M into every retained mode.

The direct sum costs M2M^2 multiplications. Splitting the samples into even and odd jj writes c^k=12(Ek+e−2πik/MOk)\hat c_k = \tfrac12\bigl(E_k + e^{-2\pi ik/M}O_k\bigr), with EE and OO the DFTs of the two half-size sequences. Repeating on each half gives log⁡2M\log_2 M levels of MM operations: the fast Fourier transform (Cooley and Tukey, 1965; from memory). For M=1024M = 1024 that is 10,24010{,}240 steps against 1,048,5761{,}048{,}576, about 100100 times fewer.

Computing it

🐍 PythonLab: the overshoot with and without sigma factors, and the DFT as a matrix
⌘/Ctrl + Enter

Now implement the sigma factors and the filtered sum yourself.

🧪 Coding exerciseExercise: sigma factors and the filtered sine sum
⌘/Ctrl + Enter

Concept checks

✅ Concept check

Why can the Fourier series of the square wave never converge uniformly?

✅ Concept check

The square wave jumps from $-1$ to $+1$ at $x = 0$. To what value does its Fourier series converge at $x = 0$?

✅ Concept check

For a unit square wave (jump from $-1$ to $+1$), what does $\max S_N$ approach as $N \to \infty$? Use $\tfrac{2}{\pi}\mathrm{Si}(\pi)$ with $\mathrm{Si}(\pi) = 1.8519$.

✅ Concept check

Why does the Fejér (Cesàro) mean of the square wave never overshoot, while the plain partial sum does?

Problems

✏️ Pen & paperPeak of $S_3$●○○

Find where the first maximum of the square-wave sum S3=4π(sin⁡x+13sin⁡3x)S_3 = \tfrac4\pi(\sin x + \tfrac13\sin 3x) occurs and its value, and compare with the formula xN=π/(N+1)x_N = \pi/(N+1).

Show worked solution

S3′=4π(cos⁡x+cos⁡3x)=4π⋅2cos⁡2xcos⁡xS_3' = \tfrac4\pi(\cos x + \cos 3x) = \tfrac4\pi\cdot2\cos 2x\cos x. The first positive zero is cos⁡2x=0\cos 2x = 0, i.e. x=π/4x = \pi/4, which equals π/(N+1)\pi/(N+1) for N=3N = 3. The value is S3(π/4)=4π(22+13⋅22)=4π⋅223=1.2004S_3(\pi/4) = \tfrac4\pi\bigl(\tfrac{\sqrt2}{2} + \tfrac13\cdot\tfrac{\sqrt2}2\bigr) = \tfrac4\pi\cdot\tfrac{2\sqrt2}{3} = 1.2004. (The next critical point cos⁡x=0\cos x = 0 at π/2\pi/2 is a minimum, 0.84880.8488.)

✏️ Pen & paperThe rms rate of the square wave●●○

Use Parseval and an integral comparison to show that the rms error of SNS_N for the square wave is about 2πN+1\tfrac{2}{\pi\sqrt{N+1}}. Evaluate at N=39N = 39.

Show worked solution

The mean square error is 12∑k odd > Nbk2=8π2∑k odd > Nk−2\tfrac12\sum_{k\text{ odd}\,\gt\,N}b_k^2 = \tfrac8{\pi^2}\sum_{k\text{ odd}\,\gt\,N}k^{-2}. The odd integers above NN are 22 apart, so the sum is about 12∫N+1∞k−2dk=12(N+1)\tfrac12\int_{N+1}^\infty k^{-2}dk = \tfrac1{2(N+1)}. The mean square error is 4π2(N+1)\tfrac{4}{\pi^2(N+1)} and the rms error 2πN+1\tfrac{2}{\pi\sqrt{N+1}}; at N=39N = 39 that is 0.6366/6.3246=0.10070.6366/6.3246 = 0.1007, against the sim’s 0.10060.1006.

✏️ Pen & paperSmoothness of $x^2$ and a four-point DFT●●○

(a) The previous lesson’s series for x2x^2 on (−π,π)(-\pi, \pi) has ak=4(−1)k/k2a_k = 4(-1)^k/k^2. Is the periodic extension continuous? Does its derivative jump? Estimate the rms error of SNS_N.

(b) Compute the DFT Xk=∑j=03xje−2πijk/4X_k = \sum_{j=0}^{3}x_je^{-2\pi ijk/4} of x=(1,2,0,−1)x = (1, 2, 0, -1) and verify Parseval’s identity ∑∣xj∣2=14∑∣Xk∣2\sum|x_j|^2 = \tfrac14\sum|X_k|^2.

Show worked solution

(a) The periodic extension of x2x^2 is continuous, since both ends equal π2\pi^2, but its slope jumps from 2π2\pi at x=πx = \pi to −2π-2\pi at x=−πx = -\pi: a corner, so m=1m = 1 and ak∼k−2a_k \sim k^{-2}, consistent with the formula. The mean square error is 12∑k>N16/k4≈83N3\tfrac12\sum_{k\gt N}16/k^4 \approx \tfrac{8}{3N^3}, so the rms error is about 1.63 N−3/21.63\,N^{-3/2}, the slope −3/2-3/2 of the triangle. (A direct numerical check at N=39N = 39 gives about 0.00660.0066 against the estimate 0.00670.0067.)

(b) With e−iπ/2=−ie^{-i\pi/2} = -i: X0=1+2+0−1=2X_0 = 1 + 2 + 0 - 1 = 2. X1=1+2(−i)+0+(−1)(i)=1−3iX_1 = 1 + 2(-i) + 0 + (-1)(i) = 1 - 3i. X2=1−2+0+1=0X_2 = 1 - 2 + 0 + 1 = 0. X3=1+2(i)+0+(−1)(−i)=1+3iX_3 = 1 + 2(i) + 0 + (-1)(-i) = 1 + 3i. Then ∑∣xj∣2=1+4+0+1=6\sum|x_j|^2 = 1 + 4 + 0 + 1 = 6 and 14(4+10+0+10)=6\tfrac14\bigl(4 + 10 + 0 + 10\bigr) = 6. Energy is conserved by the change of basis, as in the continuous case.

Key Takeaways

  • Mean-square convergence holds for any finite-energy ff (square wave: rms error 0.10060.1006 at N=39N = 39); pointwise convergence holds by Dirichlet’s theorem, to the midpoint at a jump; uniform convergence fails at a jump.
  • Gibbs: the first maximum sits at π/(N+1)\pi/(N+1) with limiting height 2πSi(π)=1.17898\tfrac2\pi\mathrm{Si}(\pi) = 1.17898, an overshoot of 8.95%8.95\% of the jump (1.179011.17901 at N=127N = 127). It narrows but never shrinks.
  • Fejér averaging (σk=1−k/(N+1)\sigma_k = 1 - k/(N+1)) uses a positive kernel and cannot overshoot, but is only first-order accurate; the Lanczos factor leaves 1.19%1.19\% and the raised cosine 0.64%0.64\%.
  • The plain sum is the orthogonal projection, best in mean square (0.05630.0563 at N=127N = 127 against 0.06920.0692 for Lanczos); filters improve the error away from the jump from 10−210^{-2} to 10−410^{-4} or better.
  • A jump in the mm-th derivative gives rms error N−(m+1/2)N^{-(m+1/2)}: measured slopes −0.487-0.487, −1.461-1.461, −3.453-3.453 for jumps in ff, f′f', f′′′f'''. A filter of order pp caps the rate at −p-p.
  • The DFT is a quadrature rule and an orthogonal change of basis, with aliasing beyond Nyquist; the FFT costs Mlog⁡2MM\log_2M instead of M2M^2.
  • Spectral fluid codes filter and dealias for these reasons; their Gibbs ringing is the same kind of symptom as Lax-Wendroff ringing, not the same mechanism.

What comes next

Everything so far used sines and cosines, the right eigenfunctions for a constant-coefficient equation on a straight interval. A pipe or a sphere gives Sturm-Liouville problems (8.2 Eigenvalue Problems & Sturm–Liouville Theory) whose eigenfunctions are Bessel functions and Legendre polynomials. The next lesson, 8.6 Orthogonal Polynomials & Special Functions, builds series in those bases and introduces the Chebyshev polynomials that spectral methods use near walls. I expect mean-square convergence and the smoothness-rate rule to survive, but I will not assume it: the lesson will check what carries over (from memory: the Chebyshev case reduces to a cosine series by x=cos⁡θx = \cos\theta, which is where the FFT comes back in).

Finished this lesson?

Mark it complete to track your progress (saved in this browser). Reading every section does this for you.

Where this leads

These later lessons build directly on this one: