S1651 of 56
0 XP
  1. Hook
  2. Predict
  3. Name it
  4. Check
  5. Explain

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?

Name it

Task 1: room modes

Loop over the integer triples (nx,ny,nz) up to the largest that could fall below fmax⁡, compute each mode's frequency from lesson 27's formula, keep those at or below fmax⁡, 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 −(yi−1−2yi+yi+1)/h2=λyi, a symmetric tridiagonal matrix whose eigenvalues λ are (ω/c)2. NumPy's eigvalsh returns them; the frequencies are cλ/2π.

Task 3: the piston's beam

Bessel's integral

J1(x)=1π∫0πcos⁡(t−xsin⁡t)dt

has a smooth periodic integrand, so the trapezoid rule converges extremely fast: 64 intervals give machine precision. Use it for the pattern |2J1(x)/x| (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
  1. The small room. Thirteen modes up to 100 Hz, starting 34.30,42.88,54.91,57.17,66.67Hz
  2. The larger room. It has 1912 modes below 500 Hz.
  3. 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
  1. The string with 200 intervals. The first and fifth modes are f1=110.002Hzf5=549.87Hz the fifth 0.026% low.
  2. Convergence. With 50 and 100 intervals the fifth mode's errors are 0.41% and 0.10%, a ratio of 4.00.
  3. The Bessel function. J1(1)=0.440051
  4. The piston's half-power angle. θ=0.1774rad=10.16∘ matching sin−1⁡(1.6163/ka).

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?

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.