-
Notifications
You must be signed in to change notification settings - Fork 6
/
plot_bp_2d.m
174 lines (161 loc) · 6.31 KB
/
plot_bp_2d.m
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
function plot_bp_2d(handles,freq_wanted)
% Plot interpolated beampattern on azimuth-elevation plane
% Load data
data = getappdata(0,'data');
gui_op = getappdata(0,'gui_op');
mic_to_bat_angle = squeeze(data.proc.mic_to_bat_angle(gui_op.current_call_idx,:,:));
if nargin == 1 || isempty(freq_wanted) %allowing optional passing in of freq
freq_wanted = str2double(get(handles.edit_bp_freq,'String'))*1e3; % beampattern frequency [Hz]
end
call_dB = nan(1,data.mic_data.num_ch_in_file);
for iM=1:data.mic_data.num_ch_in_file
if strcmp(gui_op.linlog,'rb_RMS') %use RMS
freq = data.proc.call_rms_fcenter{gui_op.current_call_idx,iM};
[~,fidx] = min(abs(freq-freq_wanted));
call_dB(iM) = data.proc.call_RMS_SPL_comp_re20uPa{gui_op.current_call_idx,iM}(fidx);
else %use the PSD
freq = data.proc.call_freq_vec{gui_op.current_call_idx,iM};
[~,fidx] = min(abs(freq-freq_wanted));
call_dB(iM) = data.proc.call_psd_dB_comp_re20uPa_withbp{gui_op.current_call_idx,iM}(fidx);
end
end
% Check for channels to be excluded
if isempty(data.proc.ch_ex{gui_op.current_call_idx})
ch_ex_manual = [];
else
ch_ex_manual = data.proc.ch_ex{gui_op.current_call_idx};
end
ch_ex_sig = find(isnan(call_dB)); % low quality channel from call extraction function
% Check for mics without location data
ch_good_loc = ~isnan(data.mic_loc(:,1))';
% Interpolation
mic_num = 1:data.mic_data.num_ch_in_file;
angle_notnanidx = ~ismember(1:data.mic_data.num_ch_in_file,...
union(ch_ex_manual,ch_ex_sig)) & ch_good_loc;
az = mic_to_bat_angle(angle_notnanidx,1);
el = mic_to_bat_angle(angle_notnanidx,2);
maxref = max(call_dB(angle_notnanidx));
[azq,elq] = meshgrid(min(az):pi/180:max(az),min(el):pi/180:max(el));
if strcmp(gui_op.interp,'rb_natural') % natural neighbor interpolation
vq = griddata(az,el,call_dB(angle_notnanidx),azq,elq,'natural');
elseif strcmp(gui_op.interp,'rb_rbf') % radial basis function interpolation
vq = rbfinterp([azq(:)';elq(:)'],rbfcreate([az(:)';el(:)'],...
call_dB(angle_notnanidx),'RBFFunction','multiquadrics'));
vq = reshape(vq,size(azq));
end
vq_norm = vq-maxref;
% Find indices within measured polygon
k = boundary(az,el,0); % outer boundary of all measured points
[in,on] = inpolygon(azq,elq,az(k),el(k));
in_smpl_poly = in|on;
clear in on
vq(~in_smpl_poly) = NaN;
vq_norm(~in_smpl_poly) = NaN;
% Update peak call amplitude
set(handles.edit_peak_db,'String',sprintf('%2.1f',maxref));
% Plot interpolated beampattern with eckert4 projection
elqm = elq;
elqm(isnan(vq_norm)) = NaN;
azqm = azq;
azqm(isnan(vq_norm)) = NaN;
if get(handles.show_bp_plot,'Value')
if isempty(handles.axes_bp.Children)
axes(handles.axes_bp);
cla(handles.axes_bp,'reset');
axesm eckert4;
else
axes(handles.axes_bp);
cla(handles.axes_bp)
end
framem('fedgecolor',200*ones(1,3)/255,'flonlimit',[-120 120]);
gridm('gcolor',190*ones(1,3)/255,'glinestyle','-');
axis off
if get(handles.checkbox_norm,'Value')==0 % if "normalized" not checked
geoshow(elqm/pi*180,azqm/pi*180,vq,'displaytype','texturemap');
cc = [gui_op.caxis_raw_current(1) gui_op.caxis_raw_current(2)];
else
geoshow(elqm/pi*180,azqm/pi*180,vq_norm,'displaytype','texturemap');
cc = [gui_op.caxis_norm_current(1) gui_op.caxis_norm_current(2)];
end
contourm(elq/pi*180,azq/pi*180,vq_norm,-3,'w','linewidth',2);
textm(el/pi*180,az/pi*180,num2str(mic_num(angle_notnanidx)'),...
'horizontalalignment','center');
caxis(cc);
colorbar('southoutside');
tightmap
end
vq_norm_min = min(vq_norm(:));
contour_vec = 0:-3:(floor(vq_norm_min/3)-1)*3;
cvec_min_idx = find(contour_vec-vq_norm_min<0,1,'first');
if isempty(handles.axes_bp_contour.Children)
axes(handles.axes_bp_contour);
cla(handles.axes_bp_contour,'reset');
axesm eckert4;
framem('fedgecolor',200*ones(1,3)/255,'flonlimit',[-180 180]);
gridm('gcolor',190*ones(1,3)/255,'glinestyle','-');
axis off
else
axes(handles.axes_bp_contour);
end
contourfm(elq/pi*180,azq/pi*180,vq_norm,contour_vec(1:cvec_min_idx),'w');
hold on
textm(el/pi*180,az/pi*180,num2str(mic_num(angle_notnanidx)'),...
'horizontalalignment','center','fontsize',10);
colorbar('southoutside','ticks',fliplr(contour_vec(1:cvec_min_idx)));
colormap(handles.axes_bp_contour,parula(cvec_min_idx-1));
caxis(handles.axes_bp_contour,[contour_vec(cvec_min_idx) 0]);
tightmap
hold off
title(['Freq: ' num2str(round(freq_wanted/1e3))])
% % Plot interpolated beampattern ==========================
% axes(handles.axes_bp);
% if get(handles.checkbox_norm,'Value')==0 % if "normalized" not checked
% himg = imagesc(azq(1,:)/pi*180,elq(:,1)/pi*180,vq);
% set(himg,'AlphaData',in_smpl_poly); % make NaN part transparent
% hold on
% caxis([gui_op.caxis_raw_current(1) gui_op.caxis_raw_current(2)]);
% else
% himg = imagesc(azq(1,:)/pi*180,elq(:,1)/pi*180,vq_norm);
% set(himg,'AlphaData',in_smpl_poly); % make NaN part transparent
% hold on
% caxis([gui_op.caxis_norm_current(1) gui_op.caxis_norm_current(2)]);
% end
% contour(azq/pi*180,elq/pi*180,vq_norm,[0 -3],'w','linewidth',2);
% plot([-90 90],[0 0],'k--');
% plot([0 0],[-90 90],'k--');
% text(az/pi*180,el/pi*180,num2str(mic_num(angle_notnanidx)'),'horizontalalignment','center');
% set(gca,'xtick',-90:30:90,'ytick',-90:30:90);
% xlabel('Azimuth (deg)');
% ylabel('Elevation (deg)');
% grid
% axis xy
% axis equal
% axis([-90 90 -90 90]);
% colormap(handles.axes_bp,parula);
% colorbar
% hold off
%
% % Plot contour beampattern ==========================
% % Set contour vector
% vq_norm_min = min(min(vq_norm));
% contour_vec = 0:-3:floor(vq_norm_min/3)*3;
% cvec_min_idx = find(contour_vec-vq_norm_min<0,1,'first');
%
% % Plot contour beampattern
% axes(handles.axes_bp_contour);
% % vq_norm(~in) = NaN;
% contourf(azq/pi*180,elq/pi*180,vq_norm,contour_vec(1:cvec_min_idx),'w');
% hold on
% plot(az/pi*180,el/pi*180,'k+');
% plot(az/pi*180,el/pi*180,'ro');
%
% xlabel('Azimuth (deg)');
% ylabel('Elevation (deg)');
% grid
% axis xy
% axis equal
% axis([floor(min(az/pi*180)/5)*5 ceil(max(az/pi*180)/5)*5 floor(min(el/pi*180)/5)*5 ceil(max(el/pi*180)/5)*5]);
% caxis(contour_vec([cvec_min_idx 1]))
% colormap(handles.axes_bp_contour,parula(cvec_min_idx));
% colorbar('southoutside')
% hold off