Skip to content

Commit f61f17c

Browse files
author
Till Rettberg
committed
Use DelayedSignal in wfs_25d_fir_prefilter
2 parents 47e3cc1 + fb2c936 commit f61f17c

9 files changed

+244
-101
lines changed

doc/readthedocs-environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: SFS-readthedocs
22
dependencies:
3-
- python>=3
3+
- python==3.5
44
- sphinx>=1.3
55
- sphinx_rtd_theme
66
- numpy

examples/time_domain.py

+30-8
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
N = 56 # number of secondary sources
1616
R = 1.5 # radius of spherical/circular array
1717
x0, n0, a0 = sfs.array.circular(N, R) # get secondary source positions
18+
fs = 44100 # sampling rate
1819

19-
# create dirac
20-
signal = [1]
20+
# unit impulse
21+
signal = [1], fs
2122

2223
# POINT SOURCE
2324
xs = [2, 2, 0] # position of virtual source
2425
t = 0.008
2526
# compute driving signals
2627
d_delay, d_weight = sfs.time.drivingfunction.wfs_25d_point(x0, n0, xs)
27-
d, t_offset = sfs.time.drivingfunction.driving_signals(d_delay, d_weight,
28-
signal)
29-
t -= t_offset
28+
d = sfs.time.drivingfunction.driving_signals(d_delay, d_weight, signal)
29+
3030
# test soundfield
3131
a = sfs.mono.drivingfunction.source_selection_point(n0, x0, xs)
3232
twin = sfs.tapering.tukey(a, .3)
@@ -48,9 +48,8 @@
4848

4949
# compute driving signals
5050
d_delay, d_weight = sfs.time.drivingfunction.wfs_25d_plane(x0, n0, npw)
51-
d, t_offset = sfs.time.drivingfunction.driving_signals(d_delay,
52-
d_weight, signal)
53-
t -= t_offset
51+
d = sfs.time.drivingfunction.driving_signals(d_delay, d_weight, signal)
52+
5453
# test soundfield
5554
a = sfs.mono.drivingfunction.source_selection_plane(n0, npw)
5655
twin = sfs.tapering.tukey(a, .3)
@@ -63,4 +62,27 @@
6362
sfs.plot.virtualsource_2d([0, 0], npw, type='plane')
6463
plt.title('impulse_pw_wfs_25d')
6564
plt.savefig('impulse_pw_wfs_25d.png')
65+
66+
# FOCUSED SOURCE
67+
xs = np.r_[0.5, 0.5, 0] # position of virtual source
68+
xref = np.r_[0, 0, 0]
69+
nfs = sfs.util.normalize_vector(xref - xs) # main n of fsource
70+
t = 0.003 # compute driving signals
71+
d_delay, d_weight = sfs.time.drivingfunction.wfs_25d_focused(x0, n0, xs)
72+
d = sfs.time.drivingfunction.driving_signals(d_delay, d_weight, signal)
73+
74+
# test soundfield
75+
a = sfs.mono.drivingfunction.source_selection_focused(nfs, x0, xs)
76+
twin = sfs.tapering.tukey(a, .3)
77+
p = sfs.time.soundfield.p_array(x0, d, twin * a0, t, grid)
78+
p = p * 100 # scale absolute amplitude
79+
80+
plt.figure(figsize=(10, 10))
81+
sfs.plot.level(p, grid, cmap=my_cmap)
82+
sfs.plot.loudspeaker_2d(x0, n0, twin)
83+
plt.grid()
84+
sfs.plot.virtualsource_2d(xs)
85+
plt.title('impulse_fs_wfs_25d')
86+
plt.savefig('impulse_fs_wfs_25d.png')
87+
6688
# plt.show()

sfs/defs.py

-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,3 @@
88

99
# tolerance used for secondary source selection
1010
selection_tolerance = 1e-6
11-
12-
# sampling frequency
13-
fs = 44100

sfs/mono/drivingfunction.py

+11-9
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def _wfs_plane(omega, x0, n0, n=[0, 1, 0], c=None):
8686
"""
8787
x0 = util.asarray_of_rows(x0)
8888
n0 = util.asarray_of_rows(n0)
89-
n = util.asarray_1d(n)
89+
n = util.normalize_vector(n)
9090
k = util.wavenumber(omega, c)
9191
return 2j * k * np.inner(n, n0) * np.exp(-1j * k * np.inner(n, x0))
9292

@@ -106,7 +106,7 @@ def wfs_25d_plane(omega, x0, n0, n=[0, 1, 0], xref=[0, 0, 0], c=None,
106106
"""
107107
x0 = util.asarray_of_rows(x0)
108108
n0 = util.asarray_of_rows(n0)
109-
n = util.asarray_1d(n)
109+
n = util.normalize_vector(n)
110110
xref = util.asarray_1d(xref)
111111
k = util.wavenumber(omega, c)
112112
return wfs_25d_preeq(omega, omalias, c) * \
@@ -179,7 +179,7 @@ def wfs_25d_preeq(omega, omalias, c):
179179
def delay_3d_plane(omega, x0, n0, n=[0, 1, 0], c=None):
180180
"""Plane wave by simple delay of secondary sources."""
181181
x0 = util.asarray_of_rows(x0)
182-
n = util.asarray_1d(n)
182+
n = util.normalize_vector(n)
183183
k = util.wavenumber(omega, c)
184184
return np.exp(-1j * k * np.inner(n, x0))
185185

@@ -191,7 +191,7 @@ def source_selection_plane(n0, n):
191191
192192
"""
193193
n0 = util.asarray_of_rows(n0)
194-
n = util.asarray_1d(n)
194+
n = util.normalize_vector(n)
195195
return np.inner(n, n0) >= defs.selection_tolerance
196196

197197

@@ -225,7 +225,7 @@ def source_selection_focused(ns, x0, xs):
225225
"""
226226
x0 = util.asarray_of_rows(x0)
227227
xs = util.asarray_1d(xs)
228-
ns = util.asarray_1d(ns)
228+
ns = util.normalize_vector(ns)
229229
ds = xs - x0
230230
return inner1d(ns, ds) >= defs.selection_tolerance
231231

@@ -251,7 +251,7 @@ def nfchoa_2d_plane(omega, x0, r0, n=[0, 1, 0], max_order=None, c=None):
251251
"""
252252
x0 = util.asarray_of_rows(x0)
253253
k = util.wavenumber(omega, c)
254-
n = util.asarray_1d(n)
254+
n = util.normalize_vector(n)
255255
phi, _, r = util.cart2sph(*n)
256256
phi0 = util.cart2sph(*x0.T)[0]
257257
M = _max_order_circular_harmonics(len(x0), max_order)
@@ -305,7 +305,7 @@ def nfchoa_25d_plane(omega, x0, r0, n=[0, 1, 0], max_order=None, c=None):
305305
"""
306306
x0 = util.asarray_of_rows(x0)
307307
k = util.wavenumber(omega, c)
308-
n = util.asarray_1d(n)
308+
n = util.normalize_vector(n)
309309
phi, _, r = util.cart2sph(*n)
310310
phi0 = util.cart2sph(*x0.T)[0]
311311
M = _max_order_circular_harmonics(len(x0), max_order)
@@ -345,7 +345,7 @@ def sdm_2d_plane(omega, x0, n0, n=[0, 1, 0], c=None):
345345
"""
346346
x0 = util.asarray_of_rows(x0)
347347
n0 = util.asarray_of_rows(n0)
348-
n = util.asarray_1d(n)
348+
n = util.normalize_vector(n)
349349
k = util.wavenumber(omega, c)
350350
return k * n[1] * np.exp(-1j * k * n[0] * x0[:, 0])
351351

@@ -361,7 +361,7 @@ def sdm_25d_plane(omega, x0, n0, n=[0, 1, 0], xref=[0, 0, 0], c=None):
361361
"""
362362
x0 = util.asarray_of_rows(x0)
363363
n0 = util.asarray_of_rows(n0)
364-
n = util.asarray_1d(n)
364+
n = util.normalize_vector(n)
365365
xref = util.asarray_1d(xref)
366366
k = util.wavenumber(omega, c)
367367
return 4j * np.exp(-1j*k*n[1]*xref[1]) / hankel2(0, k*n[1]*xref[1]) * \
@@ -420,6 +420,7 @@ def esa_edge_2d_plane(omega, x0, n=[0, 1, 0], alpha=3/2*np.pi, Nc=None, c=None):
420420
421421
"""
422422
x0 = np.asarray(x0)
423+
n = util.normalize_vector(n)
423424
k = util.wavenumber(omega, c)
424425
phi_s = np.arctan2(n[1], n[0]) + np.pi
425426
L = x0.shape[0]
@@ -477,6 +478,7 @@ def esa_edge_dipole_2d_plane(omega, x0, n=[0, 1, 0], alpha=3/2*np.pi, Nc=None, c
477478
478479
"""
479480
x0 = np.asarray(x0)
481+
n = util.normalize_vector(n)
480482
k = util.wavenumber(omega, c)
481483
phi_s = np.arctan2(n[1], n[0]) + np.pi
482484
L = x0.shape[0]

sfs/mono/source.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def plane(omega, x0, n0, grid, c=None):
489489
"""
490490
k = util.wavenumber(omega, c)
491491
x0 = util.asarray_1d(x0)
492-
n0 = util.asarray_1d(n0)
492+
n0 = util.normalize_vector(n0)
493493
grid = util.as_xyz_components(grid)
494494
return np.exp(-1j * k * np.inner(grid - x0, n0))
495495

0 commit comments

Comments
 (0)