/ concept-collection / acoustic-scattering-2d
Sign in
concept-collection / acoustic-scattering-2d
acoustic-scattering-2d / scenes / speckle.m
34 lines · 1.4 KBBlameHistoryRaw
1% A random smooth medium: many weak scatterers rather than one strong one.
2%
3% The speed field is a sum of 60 plane waves with random directions, random
4% wavenumbers around kc (radians per metre), and random phases — a
5% band-limited Gaussian random field, built here with an ordinary MATLAB loop
6% because a scene is evaluated once on the CPU and has the whole language
7% available, not the element-wise subset a compiled step is held to.
8%
9% A pulse crossing this does not scatter once and leave: it scatters weakly
10% and repeatedly, and what comes out the far side is a spread-out coda rather
11% than a clean wavefront. Turn `amp` down and the medium becomes transparent;
12% turn it up and the direct arrival disappears into the noise.
14% The field is windowed to the interior so the absorbing layer stays uniform.
15% Structure inside the sponge would scatter sound back into the domain from
16% the very place that is supposed to be swallowing it.
17function [c, sig] = medium(x, y, L, npts, c0, amp, kc, seed)
18 nm = 60;
19 rng(seed);
20 g = zeros(npts, 1);
21 for k = 1:nm
22 th = 2*pi*rand();
23 kk = kc * (0.5 + rand());
24 ph = 2*pi*rand();
25 g = g + cos(kk * (cos(th)*x + sin(th)*y) + ph);
26 end
27 g = g / sqrt(nm);
29 r = sqrt(x.^2 + y.^2);
30 window = 0.5 * (1 - tanh((r - 0.28*L) / (0.03*L)));
32 c = c0 * (1 + amp * (g .* window));
33 sig = sponge(x, y, L, 0.2*L, 1700);
34end
moveopenescclose