The modal sum of Chapter 1 needs the modes, and for a string of uniform density with fixed ends they are known. As soon as the string is not uniform, or is coupled to something, or the domain has more than one dimension and an awkward shape, they are not, and the equation has to be discretised directly. This chapter introduces the scheme that almost every wave computation in acoustics starts from, and measures what it does to pitch. ### The scheme Put nodes at $x_j = jh$, $h = 1/N$, and times $t_n = n\,\Delta t$, and replace both second derivatives by centred second differences: $$u_j^{n+1} = 2u_j^n - u_j^{n-1} + \lambda^2\big(u_{j+1}^n - 2u_j^n + u_{j-1}^n\big), \qquad \lambda = \frac{c\,\Delta t}{h}.$$ The dimensionless number $\lambda$ is the **Courant number**: the distance a wave travels in one step, measured in grid spacings. The scheme is explicit, second-order accurate in both $h$ and $\Delta t$, and needs two time levels to start. Here the driver supplies both exactly, from d'Alembert's solution at $t = 0$ and $t = -\Delta t$, so that the only error left is the scheme's. Two properties decide everything that follows, and both come from putting a single Fourier mode $u_j^n = g^n e^{ikjh}$ into the scheme. The amplification factor $g$ then satisfies $$g + g^{-1} = 2 - 4\lambda^2 \sin^2(kh/2).$$ If the right-hand side lies in $[-2, 2]$, the two roots are complex conjugates on the unit circle, $g = e^{\pm i\omega\Delta t}$, and the mode neither grows nor decays. Otherwise one root is real with magnitude above one and the mode grows exponentially. The right-hand side reaches $-2$ at the shortest wave on the grid, $kh = \pi$, exactly when $\lambda = 1$, so the scheme is **stable if and only if** $\lambda \le 1$. This is the Courant–Friedrichs–Lewy condition, and it has a plain meaning: the numerical domain of dependence, one node per step, must contain the physical one, $c\,\Delta t$ per step. Within the stable range the mode's frequency obeys the **dispersion relation** $$\sin\!\left(\frac{\omega\,\Delta t}{2}\right) = \lambda \sin\!\left(\frac{kh}{2}\right),$$ where the exact relation is $\omega = ck$. Expanding both sides for small $kh$ gives $$\frac{\omega}{ck} = 1 - \frac{(1 - \lambda^2)(kh)^2}{24} + O\big((kh)^4\big),$$ so every wave on the grid travels slightly too slowly, the shorter waves more so. With $kh = 2\pi/P$, where $P$ is the number of grid points per wavelength, the pitch error in cents is about $$-\frac{1731\,\pi^2(1 - \lambda^2)}{6P^2} \approx -\frac{2847\,(1 - \lambda^2)}{P^2}.$$ ### The magic time step At $\lambda = 1$ the leading error term vanishes, and so do all the others: the dispersion relation becomes $\omega\Delta t = kh$, which is $\omega = ck$ exactly, for every mode the grid can hold. The reason is visible in the scheme itself. At $\lambda = 1$ it reads $u_j^{n+1} + u_j^{n-1} = u_{j+1}^n + u_{j-1}^n$, and any function of the form $F(j - n) + G(j + n)$ satisfies that identically. Those are d'Alembert's two travelling waves, moving exactly one node per step. The scheme is then not an approximation to the wave equation on the grid; it is its exact solution, sampled. The lab runs a plucked string at the audio rate: the time step is one sample at 44.1 kHz, the grid has $N$ intervals, and the fundamental is 110.25 Hz, chosen so that $N = 200$ gives $\lambda = 1$ exactly. Choosing the grid therefore chooses the Courant number, $\lambda = N/200$. At $N = 200$ the recorded signal agrees with d'Alembert's solution to a relative rms error of $1.3\times10^{-12}$, which is rounding error accumulated over 110,250 steps. It agrees with d'Alembert's solution, not with the band-limited modal sum: the grid reproduces the exact solution at its nodes, corners and all, and so it also reproduces the aliasing of Chapter 1. That aliasing is harmonic here, because the fundamental was chosen so that $f_s = 400 f_0$ exactly, and every folded partial lands on another harmonic. At $N = 100$ the Courant number is $0.5$, and the error is no longer small: the relative rms difference over the last second is $0.72$. The fundamental is only 0.05 cents flat and the tenth partial 5.4 cents flat, but the partials above the twentieth are flat by tens or hundreds of cents, and the grid has no partials above the 99th at all. Listen to the two recordings: the coarse grid's string is duller, because it has lost its upper partials, and its remaining upper partials are no longer in tune with the lower ones, which gives it a faintly clangy quality. At $N = 50$ the error is 1.04 and the tenth partial is 27 cents flat. At $N = 201$, $\lambda = 1.005$, and the scheme blows up after 69 steps, 1.6 ms. The instability starts in the shortest wave on the grid, $kh = \pi$, which is exactly where the stability condition first fails, and it grows by a factor of about 1.2 per step. The clip is silenced from the moment the recording exceeds fifty times the size of the exact signal. ### Every partial, measured The run above measures the waveform. The next lab measures what a listener would hear, the pitch of each partial. Because the discrete sine vectors $\sin(n\pi j/N)$ are exact eigenvectors of the three-point difference, projecting the computed field onto one of them gives a single pure sinusoid, and `wv_peakfreq` reads its frequency off the recording. The measured frequencies are then compared with the exact $n f_0$. Unlike the previous lab, this one decouples the time step from the audio rate, so that five Courant numbers can be compared on the same grid. The largest disagreement between the measured pitch errors and the dispersion relation is below $10^{-7}$ cents, so the dispersion relation is not a model of this scheme's behaviour but an exact description of it, and the measurement procedure is accurate enough to confirm it. At $\lambda = 1$ every measured error is below $10^{-7}$ cents. The lower plot is the useful one. Against points per wavelength, the curves for every grid lie on top of each other, and at high resolution each falls with slope $-2$, as the expansion predicts. Reading off where each crosses the 5-cent line gives the resolution a string needs: about 21 points per wavelength at $\lambda = 0.5$, 16 at $\lambda = 0.75$ and 11 at $\lambda = 0.9$. At $\lambda = 0.25$ it is 23. The plot also shows how bad the scheme is at the other end. Near two points per wavelength the error is several hundred cents, more than a semitone. A grid does not represent its shortest waves inaccurately; it represents them as different waves. ### The sound of dispersion For a standing wave, dispersion is a wrong pitch. For a travelling one, it is a wrong arrival time that depends on frequency. The last lab sends a click, a Gaussian pulse about $0.03$ ms wide, round a 17.15 m loop of tube, and records it at one point as it passes, twenty times a second. The tube is periodic, the time step is one sample, and the Courant number is chosen from a list. At $\lambda = 1$ the recording is the exact pulse train, to a relative error of $3\times10^{-11}$. At $\lambda = 0.5$ each click arrives followed by a descending whistle, and by the twentieth pass the whistle has spread over more than the interval between clicks. Two effects combine. The grid cannot carry frequencies above $f_s \arcsin(\lambda)/\pi$ at all, which is 7.35 kHz at $\lambda = 0.5$ and 3.55 kHz at $\lambda = 0.25$, so the click loses its top. And the frequencies it can carry travel at the group velocity $$v_g = c\,\frac{\cos(kh/2)}{\cos(\omega\Delta t/2)},$$ which at 5 kHz and $\lambda = 0.5$ is about three quarters of the speed of sound. After 334 m that frequency arrives about 0.3 s late. The spectrogram shows it directly: each click is a falling curve, highest frequencies last, and the curves lean further with each pass. This is the characteristic sound of numerical dispersion in an explicit scheme, and it is worth learning to recognise, because it appears whenever a simulation runs for many wavelengths at too coarse a resolution. It is also the reason that the waveform error of this recording, 1.7 at $\lambda = 0.5$, says so little: the error is not noise but a smearing of each click in time, and it grows with distance. ### What this chapter establishes In one dimension the leapfrog scheme has a magic time step, $\lambda = 1$, at which it is exact. Below it, every wave is slow by an amount that depends on its length, the error in pitch is $-2847(1-\lambda^2)/P^2$ cents at $P$ points per wavelength, and between 11 and 23 points per wavelength are needed for errors below 5 cents, depending on how close to 1 the Courant number is. In two and three dimensions there is no magic time step, and Chapters 4 and 5 are about what that costs. First, though, Chapter 3 takes the magic time step seriously and removes the grid altogether.