Skip to content

Commit 14393fc

Browse files
committed
Update wfs-animation.ipynb
some suggestions - imports into dedicated cell - point source location farther and offset for more active speakers and ping pong pattern - mod some comments, e.g. add physical units - normalise with 4*pi*xs to be consistent with other examples - time_stamps not hard coded - due to normalise other vmin/vmax
1 parent 4a513f5 commit 14393fc

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

doc/examples/wfs-animation.ipynb

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,38 @@
1313
"from matplotlib import animation\n",
1414
"from IPython.display import HTML\n",
1515
"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": [
1926
"# 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",
2331
"\n",
2432
"# 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",
2735
"\n",
2836
"# Circular loudspeaker array\n",
2937
"N = 32 # number of loudspeakers\n",
30-
"R = 1.5 # radius\n",
38+
"R = 1.5 # radius [m]\n",
3139
"array = sfs.array.circular(N, R)\n",
3240
"\n",
3341
"grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.02)\n",
3442
"\n",
3543
"delays, weights, selection, secondary_source = \\\n",
3644
" 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"
3848
]
3949
},
4050
{
@@ -54,6 +64,7 @@
5464
" sfs.plot2d.loudspeakers(array.x, array.n, selection * array.a, size=0.15)\n",
5565
" return im\n",
5666
"\n",
67+
"\n",
5768
"def update_frame_pressure(i, time_stamps):\n",
5869
" t_i = time_stamps[i]\n",
5970
" p = sfs.td.synthesize(d, selection, array, secondary_source, grid=grid,\n",
@@ -62,15 +73,16 @@
6273
" return [im]\n",
6374
"\n",
6475
"\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",
6981
"\n",
7082
"fig, ax = plt.subplots(figsize=(5, 5))\n",
7183
"p = sfs.td.synthesize(d, selection, array, secondary_source, grid=grid,\n",
7284
" 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",
7486
"\n",
7587
"ani = animation.FuncAnimation(\n",
7688
" fig, partial(update_frame_pressure, time_stamps=time_stamps),\n",
@@ -86,14 +98,14 @@
8698
"metadata": {},
8799
"outputs": [],
88100
"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)"
91103
]
92104
}
93105
],
94106
"metadata": {
95107
"kernelspec": {
96-
"display_name": "Python 3 (ipykernel)",
108+
"display_name": "sfs",
97109
"language": "python",
98110
"name": "python3"
99111
},
@@ -107,7 +119,7 @@
107119
"name": "python",
108120
"nbconvert_exporter": "python",
109121
"pygments_lexer": "ipython3",
110-
"version": "3.9.5"
122+
"version": "3.13.7"
111123
}
112124
},
113125
"nbformat": 4,

0 commit comments

Comments
 (0)