|
13 | 13 | "from matplotlib import animation\n", |
14 | 14 | "from IPython.display import HTML\n", |
15 | 15 | "from functools import partial\n", |
16 | | - "from scipy.signal import unit_impulse\n", |
17 | | - "\n", |
18 | | - "\n", |
| 16 | + "from scipy.signal import unit_impulse" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": null, |
| 22 | + "id": "d5cf3220", |
| 23 | + "metadata": {}, |
| 24 | + "outputs": [], |
| 25 | + "source": [ |
19 | 26 | "# Point source\n", |
20 | | - "xs = 0, 2, 0\n", |
21 | | - "rs = np.linalg.norm(xs) # distance from origin\n", |
22 | | - "ts = rs / sfs.default.c # time-of-arrival at origin\n", |
| 27 | + "xs = 0.1, 3, 0 # yields 11 active loudspeakers and \n", |
| 28 | + "# a ping pong like excitation pattern\n", |
| 29 | + "rs = np.linalg.norm(xs) # distance from origin [m]\n", |
| 30 | + "ts = rs / sfs.default.c # time-of-arrival at origin [s]\n", |
23 | 31 | "\n", |
24 | 32 | "# Impulsive excitation\n", |
25 | | - "fs = 8000 # Adjust this to change the shape (width) of the impulse\n", |
26 | | - "signal = unit_impulse(512), fs # Band-limited pulse (e.g. sinc) can be used instead\n", |
| 33 | + "fs = 8000 # [Hz], determines width of the impulse\n", |
| 34 | + "signal = unit_impulse(512), fs\n", |
27 | 35 | "\n", |
28 | 36 | "# Circular loudspeaker array\n", |
29 | 37 | "N = 32 # number of loudspeakers\n", |
30 | | - "R = 1.5 # radius\n", |
| 38 | + "R = 1.5 # radius [m]\n", |
31 | 39 | "array = sfs.array.circular(N, R)\n", |
32 | 40 | "\n", |
33 | 41 | "grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.02)\n", |
34 | 42 | "\n", |
35 | 43 | "delays, weights, selection, secondary_source = \\\n", |
36 | 44 | " sfs.td.wfs.point_25d(array.x, array.n, xs)\n", |
37 | | - "d = sfs.td.wfs.driving_signals(delays, weights, signal)" |
| 45 | + "weights *= 4 * np.pi * rs # normalise to origin\n", |
| 46 | + "d = sfs.td.wfs.driving_signals(delays, weights, signal)\n", |
| 47 | + "# note: no WFS pre-filter is utilised" |
38 | 48 | ] |
39 | 49 | }, |
40 | 50 | { |
|
54 | 64 | " sfs.plot2d.loudspeakers(array.x, array.n, selection * array.a, size=0.15)\n", |
55 | 65 | " return im\n", |
56 | 66 | "\n", |
| 67 | + "\n", |
57 | 68 | "def update_frame_pressure(i, time_stamps):\n", |
58 | 69 | " t_i = time_stamps[i]\n", |
59 | 70 | " p = sfs.td.synthesize(d, selection, array, secondary_source, grid=grid,\n", |
|
62 | 73 | " return [im]\n", |
63 | 74 | "\n", |
64 | 75 | "\n", |
65 | | - "time_stamps = np.linspace(0.5/343, 5/343, 100) # Time sampling is different from fs defined above\n", |
66 | | - "frames = 100\n", |
67 | | - "interval = 150\n", |
68 | | - "\n", |
| 76 | + "# Movie time sampling is different from fs defined above\n", |
| 77 | + "time_stamps = np.linspace(ts-R/sfs.default.c,\n", |
| 78 | + " ts+R/sfs.default.c,\n", |
| 79 | + " 100)\n", |
| 80 | + "frames, interval = 100, 150\n", |
69 | 81 | "\n", |
70 | 82 | "fig, ax = plt.subplots(figsize=(5, 5))\n", |
71 | 83 | "p = sfs.td.synthesize(d, selection, array, secondary_source, grid=grid,\n", |
72 | 84 | " observation_time=0)\n", |
73 | | - "im = plot(d, selection, secondary_source, t=ts, ax=ax, vmin=-0.01, vmax=0.01)\n", |
| 85 | + "im = plot(d, selection, secondary_source, t=ts, ax=ax, vmin=-0.4, vmax=0.4)\n", |
74 | 86 | "\n", |
75 | 87 | "ani = animation.FuncAnimation(\n", |
76 | 88 | " fig, partial(update_frame_pressure, time_stamps=time_stamps),\n", |
|
86 | 98 | "metadata": {}, |
87 | 99 | "outputs": [], |
88 | 100 | "source": [ |
89 | | - "# Save as gif file - This might take a few minutes.\n", |
90 | | - "ani.save(\"wfs-25d-td.gif\", writer='imagemagick',fps=10, dpi=200)" |
| 101 | + "# Save as gif file - this might take a few minutes.\n", |
| 102 | + "ani.save(\"wfs-25d-td.gif\", writer='imagemagick', fps=10, dpi=200)" |
91 | 103 | ] |
92 | 104 | } |
93 | 105 | ], |
94 | 106 | "metadata": { |
95 | 107 | "kernelspec": { |
96 | | - "display_name": "Python 3 (ipykernel)", |
| 108 | + "display_name": "sfs", |
97 | 109 | "language": "python", |
98 | 110 | "name": "python3" |
99 | 111 | }, |
|
107 | 119 | "name": "python", |
108 | 120 | "nbconvert_exporter": "python", |
109 | 121 | "pygments_lexer": "ipython3", |
110 | | - "version": "3.9.5" |
| 122 | + "version": "3.13.7" |
111 | 123 | } |
112 | 124 | }, |
113 | 125 | "nbformat": 4, |
|
0 commit comments