-
Notifications
You must be signed in to change notification settings - Fork 19
/
horizontal_plane_arrays.py
151 lines (112 loc) · 5.14 KB
/
horizontal_plane_arrays.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
"""
Generates sound fields for various arrays and virtual source types.
"""
import numpy as np
import matplotlib.pyplot as plt
import sfs
dx = 0.1 # secondary source distance
N = 30 # number of secondary sources
f = 1000 # frequency
pw_angle = 20 # traveling direction of plane wave
xs = [-1.5, 0.2, 0] # position of virtual monopole
tapering = sfs.tapering.tukey # tapering window
talpha = 0.3 # parameter for tapering window
xnorm = [1, 1, 0] # normalization point for plots
grid = sfs.util.xyz_grid([-2.5, 2.5], [-1.5, 2.5], 0, spacing=0.02)
acenter = [0.3, 0.7, 0] # center and normal vector of array
anormal = sfs.util.direction_vector(np.radians(35), np.radians(90))
# angular frequency
omega = 2 * np.pi * f
# normal vector of plane wave
npw = sfs.util.direction_vector(np.radians(pw_angle), np.radians(90))
def compute_and_plot_soundfield(title):
"""Compute and plot synthesized sound field."""
print('Computing', title)
twin = tapering(selection, alpha=talpha)
p = sfs.fd.synthesize(d, twin, array, secondary_source, grid=grid)
plt.figure(figsize=(15, 15))
plt.cla()
sfs.plot2d.amplitude(p, grid, xnorm=xnorm)
sfs.plot2d.loudspeakers(array.x, array.n, twin)
sfs.plot2d.virtualsource(xs)
sfs.plot2d.virtualsource([0, 0], npw, type='plane')
plt.title(title)
plt.grid()
plt.savefig(title + '.png')
# linear array, secondary point sources, virtual monopole
array = sfs.array.linear(N, dx, center=acenter, orientation=anormal)
d, selection, secondary_source = sfs.fd.wfs.point_3d(
omega, array.x, array.n, xs)
compute_and_plot_soundfield('linear_ps_wfs_3d_point')
d, selection, secondary_source = sfs.fd.wfs.point_25d(
omega, array.x, array.n, xs, xref=xnorm)
compute_and_plot_soundfield('linear_ps_wfs_25d_point')
d, selection, secondary_source = sfs.fd.wfs.point_2d(
omega, array.x, array.n, xs)
compute_and_plot_soundfield('linear_ps_wfs_2d_point')
# linear array, secondary line sources, virtual line source
d, selection, secondary_source = sfs.fd.wfs.line_2d(
omega, array.x, array.n, xs)
compute_and_plot_soundfield('linear_ls_wfs_2d_line')
# linear array, secondary point sources, virtual plane wave
d, selection, secondary_source = sfs.fd.wfs.plane_3d(
omega, array.x, array.n, npw)
compute_and_plot_soundfield('linear_ps_wfs_3d_plane')
d, selection, secondary_source = sfs.fd.wfs.plane_25d(
omega, array.x, array.n, npw, xref=xnorm)
compute_and_plot_soundfield('linear_ps_wfs_25d_plane')
d, selection, secondary_source = sfs.fd.wfs.plane_2d(
omega, array.x, array.n, npw)
compute_and_plot_soundfield('linear_ps_wfs_2d_plane')
# non-uniform linear array, secondary point sources
array = sfs.array.linear_diff(N//3 * [dx] + N//3 * [dx/2] + N//3 * [dx],
center=acenter, orientation=anormal)
d, selection, secondary_source = sfs.fd.wfs.point_25d(
omega, array.x, array.n, xs, xref=xnorm)
compute_and_plot_soundfield('linear_nested_ps_wfs_25d_point')
d, selection, secondary_source = sfs.fd.wfs.plane_25d(
omega, array.x, array.n, npw, xref=xnorm)
compute_and_plot_soundfield('linear_nested_ps_wfs_25d_plane')
# random sampled linear array, secondary point sources
array = sfs.array.linear_random(N, dx/2, 1.5*dx, center=acenter,
orientation=anormal)
d, selection, secondary_source = sfs.fd.wfs.point_25d(
omega, array.x, array.n, xs, xref=xnorm)
compute_and_plot_soundfield('linear_random_ps_wfs_25d_point')
d, selection, secondary_source = sfs.fd.wfs.plane_25d(
omega, array.x, array.n, npw, xref=xnorm)
compute_and_plot_soundfield('linear_random_ps_wfs_25d_plane')
# rectangular array, secondary point sources
array = sfs.array.rectangular((N, N//2), dx, center=acenter, orientation=anormal)
d, selection, secondary_source = sfs.fd.wfs.point_25d(
omega, array.x, array.n, xs, xref=xnorm)
compute_and_plot_soundfield('rectangular_ps_wfs_25d_point')
d, selection, secondary_source = sfs.fd.wfs.plane_25d(
omega, array.x, array.n, npw, xref=xnorm)
compute_and_plot_soundfield('rectangular_ps_wfs_25d_plane')
# circular array, secondary point sources
N = 60
array = sfs.array.circular(N, 1, center=acenter)
d, selection, secondary_source = sfs.fd.wfs.point_25d(
omega, array.x, array.n, xs, xref=xnorm)
compute_and_plot_soundfield('circular_ps_wfs_25d_point')
d, selection, secondary_source = sfs.fd.wfs.plane_25d(
omega, array.x, array.n, npw, xref=xnorm)
compute_and_plot_soundfield('circular_ps_wfs_25d_plane')
# circular array, secondary line sources, NFC-HOA
array = sfs.array.circular(N, 1)
xnorm = [0, 0, 0]
talpha = 0 # switches off tapering
d, selection, secondary_source = sfs.fd.nfchoa.plane_2d(
omega, array.x, 1, npw)
compute_and_plot_soundfield('circular_ls_nfchoa_2d_plane')
# circular array, secondary point sources, NFC-HOA
array = sfs.array.circular(N, 1)
xnorm = [0, 0, 0]
talpha = 0 # switches off tapering
d, selection, secondary_source = sfs.fd.nfchoa.point_25d(
omega, array.x, 1, xs)
compute_and_plot_soundfield('circular_ps_nfchoa_25d_point')
d, selection, secondary_source = sfs.fd.nfchoa.plane_25d(
omega, array.x, 1, npw)
compute_and_plot_soundfield('circular_ps_nfchoa_25d_plane')