Skip to content

Commit 3bf59ac

Browse files
committed
Add automatic scaling to loudspeaker weights for plotting (#78)
* Add automatic scaling to loudspeaker weights for plotting * Change ls scaling to abs and clean up draw_loudspeakers()
1 parent db0809d commit 3bf59ac

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

SFS_plotting/draw_loudspeakers.m

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ function draw_loudspeakers(x0,dimensions,conf)
1313
% DRAW_LOUDSPEAKERS(x0,dimensions,conf) draws loudspeaker symbols or filled
1414
% points at the given secondary source positions. This can be controlled by
1515
% the conf.plot.realloudspeakers setting. The loudspeaker symbols are pointing
16-
% in their given direction.
16+
% in their given direction and are colored accordingly to their weights,
17+
% whereby the weights are scaled to an absolute maximum of 1 before.
1718
%
1819
% See also: plot_sound_field
1920

@@ -78,42 +79,41 @@ function draw_loudspeakers(x0,dimensions,conf)
7879
x0(:,2) = x0(:,3);
7980
end
8081

81-
% Weightings of the single sources
82-
win = x0(:,7);
83-
84-
% Plot only "x" at the loudspeaker positions, use this as default for all cases
82+
% Plot only "o" at the loudspeaker positions, use this as default for all cases
8583
% that are not the x-y-plane
8684
if ~p.realloudspeakers || ~(dimensions(1)&&dimensions(2))
85+
8786
if p.realloudspeakers && ~(dimensions(1)&&dimensions(2))
8887
warning('%s: Real loudspeaker can only be drawn in the x-y-plane', ...
8988
upper(mfilename));
9089
end
91-
% plot all secondary sources with the same color + symbol
90+
% Plot all secondary sources with the same color + symbol
9291
plot(x0(:,1),x0(:,2),'o', ...
9392
'MarkerFaceColor','k', ...
9493
'MarkerEdgeColor','k', ...
9594
'MarkerSize',4);
95+
9696
else
97+
98+
% Weightings of the single loudspeakers (scale maximum to 1)
99+
weights = x0(:,7) / max(abs(x0(:,7)));
97100
% Set fill color for active loudspeakers
98-
% Scale the color. sc = 1 => black. sc = 0.5 => gray.
101+
% Scale the color: sc = 1 => black, sc = 0.5 => gray.
99102
sc = 0.6;
100-
fc = [(1-sc.*win), ...
101-
(1-sc.*win), ...
102-
(1-sc.*win)];
103+
fc = [(1-sc.*weights), ...
104+
(1-sc.*weights), ...
105+
(1-sc.*weights)];
103106

107+
% Plot a real speaker symbol at the desired position
108+
% vertex coordinates with height and width after lssize
104109
w = p.lssize;
105110
h = p.lssize;
106-
107-
% Plot a real speaker symbol at the desired position
108-
% vertex coordinates
109-
%v1 = [-h/2 -h/2 0 0 -h/2 ; -w/2 w/2 w/2 -w/2 -w/2];
110-
%v2 = [0 h/2 h/2 0 ; -w/6 -w/2 w/2 w/6];
111111
v1 = [-h -h -h/2 -h/2 -h ; -w/2 w/2 w/2 -w/2 -w/2 ; 0 0 0 0 0];
112112
v2 = [-h/2 0 0 -h/2 ; -w/6 -w/2 w/2 w/6 ; 0 0 0 0 ];
113113

114114
hold on;
115115

116-
% draw loudspeakers
116+
% Draw loudspeakers
117117
for n=1:nls
118118

119119
% Get the azimuth direction of the secondary sources
@@ -122,23 +122,20 @@ function draw_loudspeakers(x0,dimensions,conf)
122122
% Rotation matrix (orientation of the speakers)
123123
% R = [cos(phi(n)) -sin(phi(n));sin(phi(n)) cos(phi(n))];
124124
R = rotation_matrix(phi);
125-
126125
for k=1:length(v1)
127126
vr1(:,k) = R * v1(:,k);
128127
end
129-
130128
for k=1:length(v2)
131129
vr2(:,k) = R * v2(:,k);
132130
end
133131

134-
% shift
132+
% Shift
135133
v01(1,:) = vr1(1,:) + x0(n,1);
136134
v01(2,:) = vr1(2,:) + x0(n,2);
137135
v02(1,:) = vr2(1,:) + x0(n,1);
138136
v02(2,:) = vr2(2,:) + x0(n,2);
139137

140-
141-
% Draw speakers
138+
% Draw loudspeakers
142139
fill(v01(1,:),v01(2,:),fc(n,:));
143140
fill(v02(1,:),v02(2,:),fc(n,:));
144141

0 commit comments

Comments
 (0)