@@ -217,6 +217,113 @@ def point_25d(omega, x0, n0, xs, xref=[0, 0, 0], c=None, omalias=None):
217217 normalize_gain = 4 * np.pi * np.linalg.norm(xs)
218218 plot(normalize_gain * d, selection, secondary_source)
219219
220+ .. plot::
221+ :context: close-figs
222+
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
229+ xref_line = 0 # reference contour is a straight line
230+
231+ # calc xref(x0):
232+ x0_ = array.x.T[np.newaxis, :]
233+ xs_ = np.array(xs)[np.newaxis, :, np.newaxis]
234+ x0xs = x0_ - xs_
235+ x0xs_length = np.linalg.norm(x0xs, axis=1)
236+ x0xs_unit = x0xs / x0xs_length
237+ n0_ = array.n.T[np.newaxis, :]
238+ xref = np.zeros_like(x0_)
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]):
242+ cosbeta = np.dot(-n0_[0, :, i], [-1, 0, 0]) # use outward SSD normal
243+ tmp = x0xs_unit[0, :, i]
244+ tmp *= -x0xs_length[0, i]
245+ tmp *= xref_line + R * cosbeta
246+ tmp /= xs_[0, 0, 0] + R * cosbeta
247+ xref[0, :, i] = x0_[0, :, i] + tmp
248+ xref = np.squeeze(xref).T
249+
250+ d, selection, secondary_source = sfs.fd.wfs.point_25d(
251+ omega, array.x, array.n, xs, xref=xref)
252+ normalize_gain = 4 * np.pi * np.linalg.norm(xs)
253+ p = sfs.fd.synthesize(d * normalize_gain,
254+ selection,
255+ array,
256+ secondary_source,
257+ grid=grid)
258+
259+ plt.rcParams['figure.figsize'] = 10, 8
260+ ax_amp, ax_lvl = plt.subplot(2, 2, 1), plt.subplot(2, 2, 2)
261+ sfs.plot2d.amplitude(p, grid, vmax=2, vmin=-2, ax=ax_amp,
262+ colorbar_kwargs={'label': 'lin'})
263+ sfs.plot2d.level(p, grid, vmax=6, vmin=-6,
264+ cmap='seismic', ax=ax_lvl,
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)
272+ # plot xref(x0) contour:
273+ ax_amp.plot(xref[:, 0][selection],
274+ xref[:, 1][selection], 'C5o', ms=4)
275+ ax_lvl.plot(xref[:, 0][selection],
276+ xref[:, 1][selection], 'C5o', ms=4)
277+ ax_amp.grid(True), ax_lvl.grid(True)
278+
279+ .. plot::
280+ :context: close-figs
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
287+ xref_dist = 4 # radius for reference contour circle with origin xs
288+
289+ # calc xref(x0):
290+ x0_ = array.x.T[np.newaxis, :]
291+ xs_ = np.array(xs)[np.newaxis, :, np.newaxis]
292+ x0xs = x0_ - xs_
293+ x0xs_length = np.linalg.norm(x0xs, axis=1)
294+ x0xs_unit = x0xs / x0xs_length
295+ xref = x0_ + (xref_dist - x0xs_length) * x0xs_unit
296+ xref = np.squeeze(xref).T
297+
298+ d, selection, secondary_source = sfs.fd.wfs.point_25d(
299+ omega, array.x, array.n, xs, xref=xref)
300+ normalize_gain = 4 * np.pi * np.linalg.norm(xs)
301+ p = sfs.fd.synthesize(d * normalize_gain,
302+ selection,
303+ array,
304+ secondary_source,
305+ grid=grid)
306+
307+ plt.rcParams['figure.figsize'] = 10, 8
308+ ax_amp, ax_lvl = plt.subplot(2, 2, 1), plt.subplot(2, 2, 2)
309+ sfs.plot2d.amplitude(p, grid, vmax=2, vmin=-2, ax=ax_amp,
310+ colorbar_kwargs={'label': 'lin'})
311+ sfs.plot2d.level(p, grid, vmax=6, vmin=-6,
312+ cmap='seismic', ax=ax_lvl,
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)
320+ # plot xref(x0) contour:
321+ ax_amp.plot(xref[:, 0][selection],
322+ xref[:, 1][selection], 'C5o', ms=4)
323+ ax_lvl.plot(xref[:, 0][selection],
324+ xref[:, 1][selection], 'C5o', ms=4)
325+ ax_amp.grid(True), ax_lvl.grid(True)
326+
220327 """
221328 x0 = _util .asarray_of_rows (x0 )
222329 n0 = _util .asarray_of_rows (n0 )
0 commit comments