-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_wreck_mean_echo.m
275 lines (233 loc) · 8.54 KB
/
check_wreck_mean_echo.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
% 2017 09 08 Check the mean echo from the shipwreck during the night to
% determine how strong it is compared to fish echoes
% Set up various paths
if isunix
addpath('~/internal_2tb/Dropbox/0_CODE/MATLAB/saveSameSize');
addpath('~/internal_2tb/Dropbox/0_CODE/MATLAB/epsutil');
addpath('~/internal_2tb/trex/trex_fish_code/Triplet_processing_toolbox');
base_save_path = '~/internal_2tb/trex/figs_results/';
base_data_path = '~/internal_2tb/trex/figs_results/';
else
addpath('F:\Dropbox\0_CODE\MATLAB\saveSameSize');
addpath('F:\Dropbox\0_CODE\MATLAB\epsutil');
addpath('F:\trex\trex_fish_code\Triplet_processing_toolbox');
base_save_path = 'F:\trex\figs_results';
base_data_path = 'F:\trex\figs_results';
end
% Set params
run_num = 131;
%ping_num = 70:2:300;
ping_num = 301:2:500;
% Set up various paths
data_path = sprintf('subset_beamform_cardioid_coherent_run%03d',run_num);
[~,script_name,~] = fileparts(mfilename('fullpath'));
save_path = fullfile(base_save_path,sprintf('%s_run%03d',script_name,run_num));
if ~exist(save_path,'dir')
mkdir(save_path);
end
% Set params
cmap = 'jet';
sm_len = 100;
axis_lim = [-4.3 -1.3 -4.5 -1.5];
norm_detail_plot = 0;
% Set up figure
fig = figure('position',[280 60 800 560]);
% Loop through each ping for averaging
beam_mf_accum = [];
cnt = 0;
for iP=1:length(ping_num)
fname = sprintf('%s_ping%04d.mat', data_path,ping_num(iP));
save_fname = sprintf('%s_run%03d_avgSincePing%04d_ping%04d',...
script_name,run_num,ping_num(1),ping_num(iP));
disp(['Processing ',fname])
A = load(fullfile(base_data_path,data_path,fname));
if iP==1
% Get plotting params
range_beam_sm = A.data.range_beam(1:sm_len:end);
[amesh,rmesh] = meshgrid(A.data.polar_angle,range_beam_sm);
[X,Y] = pol2cart(amesh/180*pi,rmesh);
% Echo level calibration
total_gain_crd_coh = A.param.gain_load -...
A.param.gain_sys -...
A.param.gain_beamform -...
A.param.gain_pc;
end
%beam_mf_accum(iP,:,:) = A.data.beam_mf_in_time;
if iP==1
beam_mf_accum = A.data.beam_mf_in_time;
else
beam_mf_accum = beam_mf_accum + A.data.beam_mf_in_time;
end
cnt = cnt+1;
% Get envelope and smooth/subsample for AVERAGED PING
%beam_mf_mean = squeeze(mean(beam_mf_accum,1));
if mod(iP,5)==0
beam_mf_mean = beam_mf_accum/cnt;
env_mean = nan(size(beam_mf_mean));
env_sm_mean = nan(size(env_mean));
for iA=1:size(env_mean,2)
env_mean(:,iA) = abs(hilbert(beam_mf_mean(:,iA)));
if sm_len==1
env_sm_mean(:,iA) = env_mean(:,iA);
else
env_sm_mean(:,iA) = smooth(env_mean(:,iA),sm_len);
end
end
env_sm_mean = env_sm_mean(1:sm_len:end,:);
% Get envelope and smooth/subsample for SINGLE PING
env = nan(size(A.data.beam_mf_in_time));
env_sm = nan(size(env));
for iA=1:size(env,2)
env(:,iA) = abs(hilbert(A.data.beam_mf_in_time(:,iA)));
if sm_len==1
env_sm(:,iA) = env(:,iA);
else
env_sm(:,iA) = smooth(env(:,iA),sm_len);
end
end
env_sm = env_sm(1:sm_len:end,:);
% Plot
figure(fig)
subplot(121) % raw ping
cla
h1 = pcolor(X/1e3,Y/1e3,20*log10(env_sm)+...
total_gain_crd_coh-3);
hold on
set(h1,'edgecolor','none');
axis equal
colormap(jet)
caxis([65 95])
colorbar('Ticks',65:10:95,'location','southoutside')
axis(axis_lim)
xlabel('Distance (km)','fontsize',14)
ylabel('Distance (km)','fontsize',14)
set(gca,'fontsize',12)
title(sprintf('Ping %04d, %02d:%02d:%02d',ping_num(iP),...
A.data.time_hh_local,A.data.time_mm_local,A.data.time_ss_local));
subplot(122) % averaged ping
cla
h1 = pcolor(X/1e3,Y/1e3,20*log10(env_sm_mean)+...
total_gain_crd_coh-3);
hold on
set(h1,'edgecolor','none');
axis equal
colormap(jet)
caxis([65 95])
colorbar('Ticks',65:10:95,'location','southoutside')
axis(axis_lim)
xlabel('Distance (km)','fontsize',14)
ylabel('Distance (km)','fontsize',14)
set(gca,'fontsize',12)
title(sprintf('Averaged since ping %04d',ping_num(1)));
%keyboard
saveSameSize_res(gcf,120,'file',fullfile(save_path,[save_fname,'.png']),...
'format','png');
end
end
%if iP==1
% beam_mf_accum = A.data.beam_mf_in_time;
%else
% beam_mf_accum = beam_mf_accum+A.data.beam_mf_in_time;
%end
if 0
% Get envelope and smooth/subsample
beam_mf_accum = beam_mf_accum/iP;
env_accum = nan(size(beam_mf_accum));
env_sm_accum = nan(size(env_accum));
for iA=1:size(env_accum,2)
env_accum(:,iA) = abs(hilbert(beam_mf_accum(:,iA)));
if sm_len==1
env_sm_accum(:,iA) = env_accum(:,iA);
else
env_sm_accum(:,iA) = smooth(env_accum(:,iA),sm_len);
end
end
env_sm_accum = env_sm_accum(1:sm_len:end,:);
% Get envelope and smooth/subsample
env = nan(size(A.data.beam_mf_in_time));
env_sm = nan(size(env));
for iA=1:size(env,2)
env(:,iA) = abs(hilbert(A.data.beam_mf_in_time(:,iA)));
if sm_len==1
env_sm(:,iA) = env(:,iA);
else
env_sm(:,iA) = smooth(env(:,iA),sm_len);
end
end
env_sm = env_sm(1:sm_len:end,:);
% Get plotting params
range_beam_sm = A.data.range_beam(1:sm_len:end);
[amesh,rmesh] = meshgrid(A.data.polar_angle,range_beam_sm);
[X,Y] = pol2cart(amesh/180*pi,rmesh);
% Echo level calibration
total_gain_crd_coh = A.param.gain_load -...
A.param.gain_sys -...
A.param.gain_beamform -...
A.param.gain_pc;
% Plot
fig = figure('position',[280 60 800 560]);
subplot(121)
h1 = pcolor(X/1e3,Y/1e3,20*log10(env_sm)+...
total_gain_crd_coh-3);
hold on
set(h1,'edgecolor','none');
axis equal
colormap(jet)
caxis([65 95])
axis(axis_lim)
xlabel('Distance (km)','fontsize',14)
ylabel('Distance (km)','fontsize',14)
set(gca,'fontsize',12)
title(['Ping ', num2str(iP)])
subplot(122)
h1 = pcolor(X/1e3,Y/1e3,20*log10(env_sm_accum)+...
total_gain_crd_coh-3);
hold on
set(h1,'edgecolor','none');
axis equal
colormap(jet)
caxis([65 95])
axis(axis_lim)
xlabel('Distance (km)','fontsize',14)
ylabel('Distance (km)','fontsize',14)
set(gca,'fontsize',12)
title('Averaged ping')
% end
end
if 0
% Plotting
% fig = figure('position',[280 60 800 560]);
% corder = get(gca,'colororder');
figure(fig)
suptitle(title_text)
h_ori = plot_small_echogram_raw(subplot(121),A,sm_len,ori_caxis,axis_lim);
caxis([65 95])
colorbar('Ticks',65:10:95,'location','southoutside')
set(gca,'fontsize',12,'xtick',-4.3:1:-1.3,'ytick',-4.5:1:-1.5);
axis([-4.3 -1.3 -4.5 -1.5]);
xlabel('Distance (km)','fontsize',16)
ylabel('Distance (km)','fontsize',16)
set(gca,'layer','top')
% Get normalizer output
plot_normalized_echogram(subplot(122),beamform_norm,meta,norm_param,norm_caxis,axis_lim);
tt = title(sprintf('sm%d, aux%dm, guard%d',...
norm_param.sm_len,norm_param.aux_m, ...
norm_param.guard_num_bw));
set(tt,'fontsize',12);
caxis([5 15])
colorbar('Ticks',5:2:15,'location','southoutside');
set(gca,'fontsize',12,'xtick',-4.3:1:-1.3,'ytick',-4.5:1:-1.5);
axis([-4.3 -1.3 -4.5 -1.5]);
xlabel('Distance (km)','fontsize',16)
ylabel('Distance (km)','fontsize',16)
set(gca,'layer','top')
saveas(fig,fullfile(save_path,[save_fname,'.fig']),'fig');
epswrite(fullfile(save_path,[save_fname,'.eps']));
saveSameSize_150(gcf,'file',fullfile(save_path,[save_fname,'.png']),...
'format','png');
% % bw version
% colormap(brewermap([],'Greys'))
% epswrite(fullfile(save_path,[save_fname,'_bw.eps']))
% saveSameSize_150(gcf,'file',fullfile(save_path,[save_fname,'_bw.png']),...
% 'format','png');
end