Skip to content

Commit 12805a1

Browse files
authored
DOC: Add sound field synthesis example as notebook
1 parent 4807ff8 commit 12805a1

File tree

4 files changed

+233
-85
lines changed

4 files changed

+233
-85
lines changed

doc/example-python-scripts.rst

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Example Python Scripts
33

44
Various example scripts are located in the directory ``doc/examples/``, e.g.
55

6-
* :download:`examples/sound_field_synthesis.py`: Illustrates the general usage
7-
of the toolbox
86
* :download:`examples/horizontal_plane_arrays.py`: Computes the sound fields
97
for various techniques, virtual sources and loudspeaker array configurations
108
* :download:`examples/animations_pulsating_sphere.py`: Creates animations of a

doc/examples.rst

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Examples
1313
.. toctree::
1414
:maxdepth: 1
1515

16+
examples/sound-field-synthesis
1617
examples/modal-room-acoustics
1718
examples/mirror-image-source-model
1819
examples/animations-pulsating-sphere
+232
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Sound Field Synthesis\n",
8+
"\n",
9+
"Illustrates the usage of the SFS toolbox for the simulation of different sound field synthesis methods."
10+
]
11+
},
12+
{
13+
"cell_type": "code",
14+
"execution_count": null,
15+
"metadata": {},
16+
"outputs": [],
17+
"source": [
18+
"import numpy as np\n",
19+
"import matplotlib.pyplot as plt \n",
20+
"import sfs"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"# Simulation parameters\n",
30+
"number_of_secondary_sources = 56\n",
31+
"frequency = 680 # in Hz\n",
32+
"pw_angle = 30 # traveling direction of plane wave in degree\n",
33+
"xs = [-2, -1, 0] # position of virtual point source in m\n",
34+
"\n",
35+
"grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.02)\n",
36+
"omega = 2 * np.pi * frequency # angular frequency\n",
37+
"npw = sfs.util.direction_vector(np.radians(pw_angle)) # normal vector of plane wave"
38+
]
39+
},
40+
{
41+
"cell_type": "markdown",
42+
"metadata": {},
43+
"source": [
44+
"Define a helper function for synthesize and plot the sound field from the given driving signals."
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": null,
50+
"metadata": {},
51+
"outputs": [],
52+
"source": [
53+
"def sound_field(d, selection, secondary_source, array, grid, tapering=True):\n",
54+
" if tapering:\n",
55+
" tapering_window = sfs.tapering.tukey(selection, alpha=0.3)\n",
56+
" else:\n",
57+
" tapering_window = sfs.tapering.none(selection)\n",
58+
" p = sfs.fd.synthesize(d, tapering_window, array, secondary_source, grid=grid)\n",
59+
" sfs.plot2d.amplitude(p, grid, xnorm=[0, 0, 0])\n",
60+
" sfs.plot2d.loudspeakers(array.x, array.n, tapering_window)"
61+
]
62+
},
63+
{
64+
"cell_type": "markdown",
65+
"metadata": {},
66+
"source": [
67+
"## Circular loudspeaker arrays\n",
68+
"\n",
69+
"In the following we show different sound field synthesis methods applied to a circular loudspeaker array."
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"radius = 1.5 # in m\n",
79+
"array = sfs.array.circular(number_of_secondary_sources, radius)"
80+
]
81+
},
82+
{
83+
"cell_type": "markdown",
84+
"metadata": {},
85+
"source": [
86+
"### Wave Field Synthesis (WFS)\n",
87+
"\n",
88+
"#### Plane wave"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": null,
94+
"metadata": {},
95+
"outputs": [],
96+
"source": [
97+
"d, selection, secondary_source = sfs.fd.wfs.plane_25d(omega, array.x, array.n, n=npw)\n",
98+
"sound_field(d, selection, secondary_source, array, grid)"
99+
]
100+
},
101+
{
102+
"cell_type": "markdown",
103+
"metadata": {},
104+
"source": [
105+
"#### Point source"
106+
]
107+
},
108+
{
109+
"cell_type": "code",
110+
"execution_count": null,
111+
"metadata": {},
112+
"outputs": [],
113+
"source": [
114+
"d, selection, secondary_source = sfs.fd.wfs.point_25d(omega, array.x, array.n, xs)\n",
115+
"sound_field(d, selection, secondary_source, array, grid)"
116+
]
117+
},
118+
{
119+
"cell_type": "markdown",
120+
"metadata": {},
121+
"source": [
122+
"### Near-Field Compensated Higher Order Ambisonics (NFC-HOA)\n",
123+
"\n",
124+
"#### Plane wave"
125+
]
126+
},
127+
{
128+
"cell_type": "code",
129+
"execution_count": null,
130+
"metadata": {},
131+
"outputs": [],
132+
"source": [
133+
"d, selection, secondary_source = sfs.fd.nfchoa.plane_25d(omega, array.x, radius, n=npw)\n",
134+
"sound_field(d, selection, secondary_source, array, grid, tapering=False)"
135+
]
136+
},
137+
{
138+
"cell_type": "markdown",
139+
"metadata": {},
140+
"source": [
141+
"#### Point source"
142+
]
143+
},
144+
{
145+
"cell_type": "code",
146+
"execution_count": null,
147+
"metadata": {},
148+
"outputs": [],
149+
"source": [
150+
"d, selection, secondary_source = sfs.fd.nfchoa.point_25d(omega, array.x, radius, xs)\n",
151+
"sound_field(d, selection, secondary_source, array, grid, tapering=False)"
152+
]
153+
},
154+
{
155+
"cell_type": "markdown",
156+
"metadata": {},
157+
"source": [
158+
"## Linear loudspeaker array\n",
159+
"\n",
160+
"In the following we show different sound field synthesis methods applied to a linear loudspeaker array."
161+
]
162+
},
163+
{
164+
"cell_type": "code",
165+
"execution_count": null,
166+
"metadata": {},
167+
"outputs": [],
168+
"source": [
169+
"spacing = 0.07 # in m\n",
170+
"array = sfs.array.linear(number_of_secondary_sources, spacing,\n",
171+
" center=[0, -0.5, 0], orientation=[0, 1, 0])"
172+
]
173+
},
174+
{
175+
"cell_type": "markdown",
176+
"metadata": {},
177+
"source": [
178+
"### Wave Field Synthesis (WFS)\n",
179+
"\n",
180+
"#### Plane wave"
181+
]
182+
},
183+
{
184+
"cell_type": "code",
185+
"execution_count": null,
186+
"metadata": {},
187+
"outputs": [],
188+
"source": [
189+
"d, selection, secondary_source = sfs.fd.wfs.plane_25d(omega, array.x, array.n, npw)\n",
190+
"sound_field(d, selection, secondary_source, array, grid)"
191+
]
192+
},
193+
{
194+
"cell_type": "markdown",
195+
"metadata": {},
196+
"source": [
197+
"#### Point source"
198+
]
199+
},
200+
{
201+
"cell_type": "code",
202+
"execution_count": null,
203+
"metadata": {},
204+
"outputs": [],
205+
"source": [
206+
"d, selection, secondary_source = sfs.fd.wfs.point_25d(omega, array.x, array.n, xs)\n",
207+
"sound_field(d, selection, secondary_source, array, grid)"
208+
]
209+
}
210+
],
211+
"metadata": {
212+
"kernelspec": {
213+
"display_name": "Python 3",
214+
"language": "python",
215+
"name": "python3"
216+
},
217+
"language_info": {
218+
"codemirror_mode": {
219+
"name": "ipython",
220+
"version": 3
221+
},
222+
"file_extension": ".py",
223+
"mimetype": "text/x-python",
224+
"name": "python",
225+
"nbconvert_exporter": "python",
226+
"pygments_lexer": "ipython3",
227+
"version": "3.5.2"
228+
}
229+
},
230+
"nbformat": 4,
231+
"nbformat_minor": 2
232+
}

doc/examples/sound_field_synthesis.py

-83
This file was deleted.

0 commit comments

Comments
 (0)