-
Notifications
You must be signed in to change notification settings - Fork 3
/
figure_12.m
251 lines (201 loc) · 8.44 KB
/
figure_12.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
% Code to generate Figure 12 of the echo statistics tutorial
%
% This code plots the beampattern PDF associated with circular apertures of
% varying size and/or frequency for 3D distribution of scatterers.
%
% Author: Wu-Jung Lee | [email protected] | APL-UW
clear
addpath './util_fcn'
save_base_path = './figs';
[~,script_name,~] = fileparts(mfilename('fullpath'));
save_path = fullfile(save_base_path,script_name);
if ~exist(save_path,'dir')
mkdir(save_path);
end
% Narrow down ka values and save results for later use. The section below
% is only evaluated once
if ~exist(sprintf('./figs/%s/%s_ka_num.mat',script_name,script_name),'file')
disp('Finding fine ka values...')
ka = 6.65:1e-2:6.7;
theta_deg = 9.5:1e-3:10.5;
theta = theta_deg/180*pi;
btheta = (2*besselj(1,ka'*sin(theta))./(ka'*sin(theta))).^2;
btheta_log = 20*log10(btheta);
figure
plot(theta/pi*180,btheta_log)
xlabel('Polar angle (^o)');
ylabel('2-way beampattern');
grid
% Full beamwidth 1 deg
ka = 132.7:1e-5:132.8;
theta_deg_want = 0.5;
theta_deg = theta_deg_want-0.005:1e-6:theta_deg_want+0.005;
theta = theta_deg/180*pi;
btheta = (2*besselj(1,ka'*sin(theta))./(ka'*sin(theta))).^2;
btheta_log = 20*log10(btheta);
[~,idx_3db] = min(abs(btheta_log-(-3)),[],2);
[~,idx_ka] = min(abs(theta_deg(idx_3db)-theta_deg_want));
ka_want = ka(idx_ka);
btheta_want = (2*besselj(1,ka_want'*sin(theta))./(ka_want'*sin(theta))).^2;
ka_1deg = ka_want;
% Full beamwidth 5 deg
ka = 26.5:1e-5:26.6;
theta_deg_want = 2.5;
theta_deg = theta_deg_want-0.005:1e-6:theta_deg_want+0.005;
theta = theta_deg/180*pi;
btheta = (2*besselj(1,ka'*sin(theta))./(ka'*sin(theta))).^2;
btheta_log = 20*log10(btheta);
[~,idx_3db] = min(abs(btheta_log-(-3)),[],2);
[~,idx_ka] = min(abs(theta_deg(idx_3db)-theta_deg_want));
ka_want = ka(idx_ka);
btheta_want = (2*besselj(1,ka_want'*sin(theta))./(ka_want'*sin(theta))).^2;
ka_5deg = ka_want;
% Full beamwidth 10 deg
ka = 13.2:1e-5:13.3;
theta_deg_want = 5;
theta_deg = theta_deg_want-0.005:1e-6:theta_deg_want+0.005;
theta = theta_deg/180*pi;
btheta = (2*besselj(1,ka'*sin(theta))./(ka'*sin(theta))).^2;
btheta_log = 20*log10(btheta);
[~,idx_3db] = min(abs(btheta_log-(-3)),[],2);
[~,idx_ka] = min(abs(theta_deg(idx_3db)-theta_deg_want));
ka_want = ka(idx_ka);
btheta_want = (2*besselj(1,ka_want'*sin(theta))./(ka_want'*sin(theta))).^2;
ka_10deg = ka_want;
% Full beamwidth 3 deg
ka = 44.2:1e-5:44.3;
theta_deg_want = 1.5;
theta_deg = theta_deg_want-0.005:1e-6:theta_deg_want+0.005;
theta = theta_deg/180*pi;
btheta = (2*besselj(1,ka'*sin(theta))./(ka'*sin(theta))).^2;
btheta_log = 20*log10(btheta);
[~,idx_3db] = min(abs(btheta_log-(-3)),[],2);
[~,idx_ka] = min(abs(theta_deg(idx_3db)-theta_deg_want));
ka_want = ka(idx_ka);
btheta_want = (2*besselj(1,ka_want'*sin(theta))./(ka_want'*sin(theta))).^2;
ka_3deg = ka_want;
% Full beamwidth 20 deg
ka = 6.65:1e-5:6.7;
theta_deg_want = 10;
theta_deg = theta_deg_want-0.005:1e-6:theta_deg_want+0.005;
theta = theta_deg/180*pi;
btheta = (2*besselj(1,ka'*sin(theta))./(ka'*sin(theta))).^2;
btheta_log = 20*log10(btheta);
[~,idx_3db] = min(abs(btheta_log-(-3)),[],2);
[~,idx_ka] = min(abs(theta_deg(idx_3db)-theta_deg_want));
ka_want = ka(idx_ka);
btheta_want = (2*besselj(1,ka_want'*sin(theta))./(ka_want'*sin(theta))).^2;
ka_20deg = ka_want;
% Save ka numbers
save(fullfile(save_path,[script_name,'_ka_num.mat']),...
'ka_*deg');
end
% Plot pb
if ~exist(sprintf('./figs/%s/%s_b_pb.mat',script_name,script_name),'file')
disp('Calculating pb(b), this is gonna take a while...')
b_num = 5e4;
b_start_log = -7;
b_end_log = 0;
[b_1deg,pb_1deg] = calc_pb_log(ka_1deg,b_start_log,b_end_log,b_num);
[b_3deg,pb_3deg] = calc_pb_log(ka_3deg,b_start_log,b_end_log,b_num);
[b_5deg,pb_5deg] = calc_pb_log(ka_5deg,b_start_log,b_end_log,b_num);
[b_10deg,pb_10deg] = calc_pb_log(ka_10deg,b_start_log,b_end_log,b_num);
% [b_20deg,pb_20deg] = calc_pb_log(ka_20deg,b_start_log,b_end_log,b_num);
save(fullfile(save_path,[script_name,'_b_pb.mat']),...
'b_*deg','pb_*deg');
else
load(fullfile(save_path,[script_name,'_b_pb.mat']));
end
% Individual Pb plots shown in the tutorial =========
figure
loglog(b_1deg,pb_1deg,'k','linewidth',1)
axis([1e-7 2e0 1e-4 1e8])
set(gca,'fontsize',16)
ylabel('$p_b(b)$','Interpreter','LaTex','fontsize',24);
xlabel('$b$','Interpreter','LaTex','fontsize',24);
title('P_b(b), full beamwidth = 1^o');
saveas(gcf,fullfile(save_path,[script_name,'_b_pb_1deg.fig']),'fig');
saveSameSize(gcf,'file',fullfile(save_path,[script_name,'_b_pb_1deg.png']),...
'format','png','renderer','painters');
figure
loglog(b_3deg,pb_3deg,'k','linewidth',1)
axis([1e-7 2e0 1e-4 1e8])
set(gca,'fontsize',16)
ylabel('$p_b(b)$','Interpreter','LaTex','fontsize',24);
xlabel('$b$','Interpreter','LaTex','fontsize',24);
title('P_b(b), full beamwidth = 3^o');
saveas(gcf,fullfile(save_path,[script_name,'_b_pb_3deg.fig']),'fig');
saveSameSize(gcf,'file',fullfile(save_path,[script_name,'_b_pb_3deg.png']),...
'format','png','renderer','painters');
figure
loglog(b_5deg,pb_5deg,'k','linewidth',1)
axis([1e-7 2e0 1e-4 1e8])
set(gca,'fontsize',16)
ylabel('$p_b(b)$','Interpreter','LaTex','fontsize',24);
xlabel('$b$','Interpreter','LaTex','fontsize',24);
title('P_b(b), full beamwidth = 5^o');
saveas(gcf,fullfile(save_path,[script_name,'_b_pb_5deg.fig']),'fig');
saveSameSize(gcf,'file',fullfile(save_path,[script_name,'_b_pb_5deg.png']),...
'format','png','renderer','painters');
figure
loglog(b_10deg,pb_10deg,'k','linewidth',1)
axis([1e-7 2e0 1e-4 1e8])
set(gca,'fontsize',16)
ylabel('$p_b(b)$','Interpreter','LaTex','fontsize',24);
xlabel('$b$','Interpreter','LaTex','fontsize',24);
title('P_b(b), full beamwidth = 10^o');
saveas(gcf,fullfile(save_path,[script_name,'_b_pb_10deg.fig']),'fig');
saveSameSize(gcf,'file',fullfile(save_path,[script_name,'_b_pb_10deg.png']),...
'format','png','renderer','painters');
% Other interesting figures ============================
figure
loglog(b_10deg,pb_10deg)
hold on
loglog(b_5deg,pb_5deg)
loglog(b_3deg,pb_3deg)
loglog(b_1deg,pb_1deg)
axis([1e-7 1e0 1e-4 1e8])
xlabel('Echo amplitude');
ylabel('PDF');
legend('20^o','10^o','5^o','3^o','1^o','location','southwest');
title('P_b(b), different full beamwidth');
saveas(gcf,fullfile(save_path,[script_name,'_b_pb_all.fig']),'fig');
saveSameSize(gcf,'file',fullfile(save_path,[script_name,'_b_pb_all.png']),...
'format','png','renderer','painters');
figure
loglog(b_10deg,pb_10deg,'k:','linewidth',1.5)
hold on
loglog(b_5deg,pb_5deg,'k--')
loglog(b_3deg,pb_3deg,'k-.')
loglog(b_1deg,pb_1deg,'k');
axis([1e-7 1e0 1e-4 1e8])
xlabel('Echo amplitude');
ylabel('PDF');
legend('20^o','10^o','5^o','3^o','1^o','location','southwest');
title('P_b(b), different full beamwidth');
saveas(gcf,fullfile(save_path,[script_name,'_b_pb_all_bw.fig']),'fig');
saveSameSize(gcf,'file',fullfile(save_path,[script_name,'_b_pb_all_bw.png']),...
'format','png','renderer','painters');
% For verification of ka numbers
theta = (0:1e-3:12)/180*pi;
btheta_1deg = (2*besselj(1,ka_1deg*sin(theta))./(ka_1deg*sin(theta))).^2;
btheta_3deg = (2*besselj(1,ka_3deg*sin(theta))./(ka_3deg*sin(theta))).^2;
btheta_5deg = (2*besselj(1,ka_5deg*sin(theta))./(ka_5deg*sin(theta))).^2;
btheta_10deg = (2*besselj(1,ka_10deg*sin(theta))./(ka_10deg*sin(theta))).^2;
% btheta_20deg = (2*besselj(1,ka_20deg*sin(theta))./(ka_20deg*sin(theta))).^2;
figure
% plot(theta/pi*180,20*log10(btheta_20deg),'k','linewidth',1.5)
plot(theta/pi*180,20*log10(btheta_10deg),'k:','linewidth',1.5)
hold on
plot(theta/pi*180,20*log10(btheta_5deg),'k--');
plot(theta/pi*180,20*log10(btheta_3deg),'k-.');
plot(theta/pi*180,20*log10(btheta_1deg),'k');
xlabel('Polar angle (^o)')
ylabel('2-way beampattern (dB)');
title('Beampattern for different ka/beamwidth')
ylim([-5 0])
grid
legend('20^o beam','10^o beam','5^o beam','3^o beam','1^o beam');
saveas(gcf,fullfile(save_path,[script_name,'_bp_all.fig']),'fig');
saveSameSize(gcf,'file',fullfile(save_path,[script_name,'_bp_all.png']),...
'format','png','renderer','painters');