Skip to content

Commit a175ad8

Browse files
committed
Update wfs.py
- add WFS prefilter note - bandlimited Dirac impulse for nicer plots - finer grid for nicer plots - use cmap='Blues' for nicer plots - make point source normalization consistent with frequency domain
1 parent c60b86d commit a175ad8

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

sfs/td/wfs.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import matplotlib.pyplot as plt
99
import numpy as np
1010
import sfs
11-
from scipy.signal import unit_impulse
11+
from scipy.signal import unit_impulse, firwin
1212
1313
# Plane wave
1414
npw = sfs.util.direction_vector(np.radians(-45))
@@ -26,19 +26,27 @@
2626
2727
# Impulsive excitation
2828
fs = 44100
29-
signal = unit_impulse(512), fs
29+
# either with: signal = unit_impulse(512), fs
30+
# or with: bandlimited Dirac, i.e. a linear-phase lowpass FIR
31+
Nlp = 2**10 + 1
32+
tlp = (Nlp/2) / fs
33+
signal = firwin(numtaps=Nlp,
34+
cutoff=16000,
35+
window=('kaiser', 4),
36+
pass_zero='lowpass',
37+
scale=True, fs=fs), fs
3038
3139
# Circular loudspeaker array
3240
N = 32 # number of loudspeakers
3341
R = 1.5 # radius
3442
array = sfs.array.circular(N, R)
3543
36-
grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.02)
44+
grid = sfs.util.xyz_grid([-2, 2], [-2, 2], 0, spacing=0.01)
3745
3846
def plot(d, selection, secondary_source, t=0):
3947
p = sfs.td.synthesize(d, selection, array, secondary_source, grid=grid,
4048
observation_time=t)
41-
sfs.plot2d.level(p, grid)
49+
sfs.plot2d.level(p, grid, cmap='Blues')
4250
sfs.plot2d.loudspeakers(array.x, array.n,
4351
selection * array.a, size=0.15)
4452
@@ -108,7 +116,8 @@ def plane_25d(x0, n0, n=[0, 1, 0], xref=[0, 0, 0], c=None):
108116
delays, weights, selection, secondary_source = \
109117
sfs.td.wfs.plane_25d(array.x, array.n, npw)
110118
d = sfs.td.wfs.driving_signals(delays, weights, signal)
111-
plot(d, selection, secondary_source)
119+
# note that WFS prefilter is not included
120+
plot(d, selection, secondary_source, t=tlp)
112121
113122
"""
114123
if c is None:
@@ -187,8 +196,10 @@ def point_25d(x0, n0, xs, xref=[0, 0, 0], c=None):
187196
188197
delays, weights, selection, secondary_source = \
189198
sfs.td.wfs.point_25d(array.x, array.n, xs)
199+
weights *= 4*np.pi*rs # normalize
190200
d = sfs.td.wfs.driving_signals(delays, weights, signal)
191-
plot(d, selection, secondary_source, t=ts)
201+
# note that WFS prefilter is not included
202+
plot(d, selection, secondary_source, t=ts+tlp)
192203
193204
"""
194205
if c is None:
@@ -281,8 +292,10 @@ def point_25d_legacy(x0, n0, xs, xref=[0, 0, 0], c=None):
281292
282293
delays, weights, selection, secondary_source = \
283294
sfs.td.wfs.point_25d(array.x, array.n, xs)
295+
weights *= 4*np.pi*rs # normalize
284296
d = sfs.td.wfs.driving_signals(delays, weights, signal)
285-
plot(d, selection, secondary_source, t=ts)
297+
# note that WFS prefilter is not included
298+
plot(d, selection, secondary_source, t=ts+tlp)
286299
287300
"""
288301
if c is None:
@@ -363,8 +376,10 @@ def focused_25d(x0, n0, xs, ns, xref=[0, 0, 0], c=None):
363376
364377
delays, weights, selection, secondary_source = \
365378
sfs.td.wfs.focused_25d(array.x, array.n, xf, nf)
379+
weights *= 4*np.pi*rs # normalize
366380
d = sfs.td.wfs.driving_signals(delays, weights, signal)
367-
plot(d, selection, secondary_source, t=tf)
381+
# note that WFS prefilter is not included
382+
plot(d, selection, secondary_source, t=tf+tlp)
368383
369384
"""
370385
if c is None:

0 commit comments

Comments
 (0)