24
24
grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.02)
25
25
26
26
array = sfs.array.circular(N=32, R=R)
27
+ array2 = sfs.array.circular(N=64, R=R)
27
28
28
29
def plot(d, selection, secondary_source):
29
30
p = sfs.fd.synthesize(d, selection, array, secondary_source, grid=grid)
@@ -220,39 +221,38 @@ def point_25d(omega, x0, n0, xs, xref=[0, 0, 0], c=None, omalias=None):
220
221
.. plot::
221
222
:context: close-figs
222
223
223
- array = sfs.array.circular(N=128, R=R)
224
- f = 343*4 # Hz
225
- omega = 2 * np.pi * f # rad/s
226
-
227
- # example is hard coded for a point source on negative x-axis:
228
- xs = -4, 0, 0
224
+ xs = -4, 0, 0 # point source on negative x-axis
229
225
xref_line = 0 # reference contour is a straight line
230
226
231
- # calc xref(x0):
232
- x0_ = array.x.T[np.newaxis, :]
233
- xs_ = np.array(xs)[np.newaxis, :, np.newaxis]
234
- x0xs = x0_ - xs_
227
+ lmb = 1 / 4 # m
228
+ f = sfs.default.c / lmb # Hz
229
+ omega = 2 * np.pi * f # rad/s
230
+
231
+ # calc reference contour xref(x0):
232
+ x0_tmp = array2.x.T[np.newaxis, :]
233
+ xs_tmp = np.array(xs)[np.newaxis, :, np.newaxis]
234
+ x0xs = x0_tmp - xs_tmp
235
235
x0xs_length = np.linalg.norm(x0xs, axis=1)
236
236
x0xs_unit = x0xs / x0xs_length
237
- n0_ = array .n.T[np.newaxis, :]
238
- xref = np.zeros_like(x0_ )
237
+ n0_ = array2 .n.T[np.newaxis, :]
238
+ xref = np.zeros_like(x0_tmp )
239
239
# cf. https://github.com/spatialaudio/wfs_chapter_hda/blob/master/python/wfs25d_circSSD.py#L91 # noqa
240
- # hard coded for a point source on negative x-axis
241
- for i in range(array .x.shape[0]):
240
+ # code is valid for a virtual point source on negative x-axis:
241
+ for i in range(array2 .x.shape[0]):
242
242
cosbeta = np.dot(-n0_[0, :, i], [-1, 0, 0]) # use outward SSD normal
243
243
tmp = x0xs_unit[0, :, i]
244
244
tmp *= -x0xs_length[0, i]
245
245
tmp *= xref_line + R * cosbeta
246
- tmp /= xs_ [0, 0, 0] + R * cosbeta
247
- xref[0, :, i] = x0_ [0, :, i] + tmp
246
+ tmp /= xs_tmp [0, 0, 0] + R * cosbeta
247
+ xref[0, :, i] = x0_tmp [0, :, i] + tmp
248
248
xref = np.squeeze(xref).T
249
249
250
250
d, selection, secondary_source = sfs.fd.wfs.point_25d(
251
- omega, array .x, array .n, xs, xref=xref)
251
+ omega, array2 .x, array2 .n, xs, xref=xref)
252
252
normalize_gain = 4 * np.pi * np.linalg.norm(xs)
253
253
p = sfs.fd.synthesize(d * normalize_gain,
254
254
selection,
255
- array ,
255
+ array2 ,
256
256
secondary_source,
257
257
grid=grid)
258
258
@@ -263,12 +263,12 @@ def point_25d(omega, x0, n0, xs, xref=[0, 0, 0], c=None, omalias=None):
263
263
sfs.plot2d.level(p, grid, vmax=6, vmin=-6,
264
264
cmap='seismic', ax=ax_lvl,
265
265
colorbar_kwargs={'label': 'dB'})
266
- sfs.plot2d.loudspeakers(array .x, array .n,
267
- selection * array .a,
268
- size=0.15 , ax=ax_amp)
269
- sfs.plot2d.loudspeakers(array .x, array .n,
270
- selection * array .a,
271
- size=0.15 , ax=ax_lvl)
266
+ sfs.plot2d.loudspeakers(array2 .x, array2 .n,
267
+ selection * array2 .a,
268
+ size=0.125 , ax=ax_amp)
269
+ sfs.plot2d.loudspeakers(array2 .x, array2 .n,
270
+ selection * array2 .a,
271
+ size=0.125 , ax=ax_lvl)
272
272
# plot xref(x0) contour:
273
273
ax_amp.plot(xref[:, 0][selection],
274
274
xref[:, 1][selection], 'C5o', ms=4)
@@ -279,28 +279,28 @@ def point_25d(omega, x0, n0, xs, xref=[0, 0, 0], c=None, omalias=None):
279
279
.. plot::
280
280
:context: close-figs
281
281
282
- f = 343*4 # Hz
283
- omega = 2 * np.pi * f # rad/s
284
-
285
- # example is hard coded for a point source on negative x-axis:
286
- xs = -4, 0, 0
282
+ xs = -4, 0, 0 # point source on negative x-axis
287
283
xref_dist = 4 # radius for reference contour circle with origin xs
288
284
289
- # calc xref(x0):
290
- x0_ = array.x.T[np.newaxis, :]
291
- xs_ = np.array(xs)[np.newaxis, :, np.newaxis]
292
- x0xs = x0_ - xs_
285
+ lmb = 1 / 4 # m
286
+ f = sfs.default.c / lmb # Hz
287
+ omega = 2 * np.pi * f # rad/s
288
+
289
+ # calc reference contour xref(x0):
290
+ x0_tmp = array2.x.T[np.newaxis, :]
291
+ xs_tmp = np.array(xs)[np.newaxis, :, np.newaxis]
292
+ x0xs = x0_tmp - xs_tmp
293
293
x0xs_length = np.linalg.norm(x0xs, axis=1)
294
294
x0xs_unit = x0xs / x0xs_length
295
- xref = x0_ + (xref_dist - x0xs_length) * x0xs_unit
295
+ xref = x0_tmp + (xref_dist - x0xs_length) * x0xs_unit
296
296
xref = np.squeeze(xref).T
297
297
298
298
d, selection, secondary_source = sfs.fd.wfs.point_25d(
299
- omega, array .x, array .n, xs, xref=xref)
299
+ omega, array2 .x, array2 .n, xs, xref=xref)
300
300
normalize_gain = 4 * np.pi * np.linalg.norm(xs)
301
301
p = sfs.fd.synthesize(d * normalize_gain,
302
302
selection,
303
- array ,
303
+ array2 ,
304
304
secondary_source,
305
305
grid=grid)
306
306
@@ -311,12 +311,12 @@ def point_25d(omega, x0, n0, xs, xref=[0, 0, 0], c=None, omalias=None):
311
311
sfs.plot2d.level(p, grid, vmax=6, vmin=-6,
312
312
cmap='seismic', ax=ax_lvl,
313
313
colorbar_kwargs={'label': 'dB'})
314
- sfs.plot2d.loudspeakers(array .x, array .n,
315
- selection * array .a,
316
- size=0.15 , ax=ax_amp)
317
- sfs.plot2d.loudspeakers(array .x, array .n,
318
- selection * array .a,
319
- size=0.15 , ax=ax_lvl)
314
+ sfs.plot2d.loudspeakers(array2 .x, array2 .n,
315
+ selection * array2 .a,
316
+ size=0.125 , ax=ax_amp)
317
+ sfs.plot2d.loudspeakers(array2 .x, array2 .n,
318
+ selection * array2 .a,
319
+ size=0.125 , ax=ax_lvl)
320
320
# plot xref(x0) contour:
321
321
ax_amp.plot(xref[:, 0][selection],
322
322
xref[:, 1][selection], 'C5o', ms=4)
0 commit comments