S16 · Lesson 51 · Acoustics lab
Three computations in NumPy: listing a room's modes and checking Weyl's count, finding a string's modes from a finite-difference eigenvalue problem and measuring its second-order accuracy, and computing a piston's directivity from Bessel's integral to find its beamwidth
Acoustic design software does three things over and over: it finds resonances, it solves discretized wave equations, and it evaluates radiation patterns. In this lab you'll write a small version of each and test it against an exact answer: room modes counted one by one against Weyl's formula, a string's modes from a matrix eigenvalue problem against the exact harmonic series, and a loudspeaker's beam from a Bessel function you compute yourself.
Predict
You find a string's modes by replacing the second derivative with the second difference on N intervals. As N doubles, how does the error of the fifth mode change?
The second difference has a truncation error proportional to h² (A13), so the eigenvalues, and the mode frequencies, converge with second-order accuracy: halving the step cuts the error by four. Higher modes have shorter wavelengths, fewer points per wavelength and larger errors, about in relative terms.
Name it
Task 1: room modes
Loop over the integer triples up to the largest that could fall below , compute each mode's frequency from lesson 27's formula, keep those at or below , and sort them. Then compare the count with Weyl's estimate.
Task 2: string modes by finite differences
With N intervals of width h = L/N and fixed ends, the interior displacements satisfy , a symmetric tridiagonal matrix whose eigenvalues λ are . NumPy's eigvalsh returns them; the frequencies are .
Task 3: the piston's beam
Bessel's integral
has a smooth periodic integrand, so the trapezoid rule converges extremely fast: 64 intervals give machine precision. Use it for the pattern (lesson 16), then bisect for the half-power angle.
Worked example
What should task 1 report for the 5 × 4 × 3 m room, and for a 7.3 × 5.1 × 3.4 m room up to 500 Hz?
Show the solution
- The small room. Thirteen modes up to 100 Hz, starting
- The larger room. It has 1912 modes below 500 Hz.
- Weyl's estimate. It gives 1919, within 0.4%.
Answer the 5 × 4 × 3 m room has 13 modes up to 100 Hz, starting at 34.30 Hz; the larger room has 1912 modes below 500 Hz, against Weyl's 1919.
Worked example
What should tasks 2 and 3 report for the 0.65 m, 110 Hz string and the ka = 9.16 piston?
Show the solution
- The string with 200 intervals. The first and fifth modes are the fifth 0.026% low.
- Convergence. With 50 and 100 intervals the fifth mode's errors are 0.41% and 0.10%, a ratio of 4.00.
- The Bessel function.
- The piston's half-power angle. matching .
Answer with 200 intervals the string's first mode is 110.002 Hz and its fifth 549.87 Hz, and the error falls by 4.00 each time the step halves; J₁(1) = 0.440051, and the half-power angle is 0.1774 rad (10.16°).
Check
Step 1. Write room_modes and weyl: count a room's modes two ways.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 2. Write string_modes: a string's resonances from a finite-difference eigenvalue problem.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Step 3. Write J1, directivity and half_power_angle: a piston's beam from Bessel's integral.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does the trapezoid rule give Bessel's integral to machine precision with so few points?
The integrand of Bessel's integral is a smooth, periodic function of t over a full period of its extension, and for periodic analytic functions the trapezoid rule's error doesn't fall as a power of the step but exponentially: the errors from the two ends of each interval cancel term by term in the Euler–Maclaurin expansion, because every derivative matches at the ends. In effect the rule integrates exactly every Fourier component up to the number of points, and the integrand's Fourier coefficients decay faster than any power. A few dozen points therefore give sixteen digits, while a non-periodic integrand would need thousands for the same accuracy.
Practice
Keep practicing
3 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.