-
Notifications
You must be signed in to change notification settings - Fork 0
/
plotimp.m
293 lines (281 loc) · 11.8 KB
/
plotimp.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
function plotimp(imps,varargin)
% author: Ainray
% date: 20160311
% bug-report: wwzhang0421@163.com
% update date: 20160314, by Ainray
% 20160325, by Ainray
% version:1.2.1
% introduction: function for ploting impulse in batch
% input:
% imps, array of EIR structures , if 'CMP' mode is on, imps is
% matrix of EIR structures, the same column has different
% frequencies but the same point.
%
% (optional parameter-value pairs)
% 'Phase',+/-1 flip the signal up and down, i.e., phase reverse
% 'NPlotPerPage',8 number of subplots per figure
% 'SamplingRate',16000 sampling rate
% 'Width', width, the figure width
% 'Heigth',heigh, the figure height
% 'Length',1600, the length of displayed impulse
%
% 'Xscale','log'/'linear' the x axis scale
% 'Yscale','log'/'linear' the y axis scale
% 'Xlabel',xlabel, the x label
% 'Ylabel',ylabel the y label
% 'Color', color line type and color scheme
% 'Peak' false whether plot peak or not
% 'Cmp', false multiple frequcies or not
% 'Visibility', 'on' whether the figure is visible
% 'Print', false whether export figure as jpeg or other format
% 'Format', '-jpg' the exported image format
% 'Quality','-m3', the resolution, '-m3' is for 64bit
% OS and more than 4GB memeory, If you
% run on 32-bit, '-m2' is recommend.
% 'Offset', 1 the build-in nameing scheme for exported
% image have a order number at the first,
% the default is always starting with 1
% you change it by set 'Offset' by other value
%
% 'Fit', false whether plot fitting EIR or not
p=inputParser;
defnppp=12; % default number of pictures per page
deffs=16000; % default sampling rate
defwd=1440; % default width
defh=900; % default height
deflen=1600; % default impulse length (samples)
expectedscale={'linear','log'};
defxscale='linear'; % default x axis scale.
defyscale='linear'; % default y axis scale.
defxlabel='Time (s)';
defylabel='Amplitude (\Omega/m^2/s)';
defclr={'r','b','g','m','k','y','c','w'};
addRequired(p, 'imps', @isstruct);
addOptional(p, 'Phase',1,@isnumeric);
addOptional(p, 'NPlotPerPage',defnppp,@isnumeric);
addOptional(p, 'SamplingRate', deffs, @isnumeric);
addOptional(p, 'Length', deflen, @isnumeric);
addOptional(p, 'Width', defwd, @isnumeric);
addOptional(p, 'Height', defh, @isnumeric);
addOptional(p, 'Xscale', defxscale, @(x) any(validatestring(x,expectedscale)));
addOptional(p, 'Yscale', defyscale, @(x) any(validatestring(x,expectedscale)));
addOptional(p, 'Xlabel', defxlabel, @isstr);
addOptional(p, 'Ylabel', defylabel, @isstr);
addOptional(p, 'Color', defclr, @iscell);
addOptional(p, 'Peak',false,@islogical);
addOptional(p, 'Cmp',false,@islogical);
addOptional(p, 'Visibility','on',@isstr);
addOptional(p, 'Print', false, @islogical)
addOptional(p, 'Format','-jpg',@isstr);
addOptional(p, 'Quality','-m3',@isstr);
addOptional(p, 'Offset',0,@isnumeric);
addOptional(p, 'Fit',false,@islogical);
parse(p,imps,varargin{:});
phf=p.Results.Phase;
nppp=p.Results.NPlotPerPage;
len=p.Results.Length;
width=p.Results.Width;
height=p.Results.Height;
fs=p.Results.SamplingRate;
clr=p.Results.Color;
xscale=p.Results.Xscale;
yscale=p.Results.Yscale;
xlabel=p.Results.Xlabel;
ylabel=p.Results.Ylabel;
visibility=p.Results.Visibility;
ispeak=p.Results.Peak;
iscmp=p.Results.Cmp;
isprint=p.Results.Print;
fmt=p.Results.Format;
qual=p.Results.Quality;
offset=p.Results.Offset;
isfit=p.Results.Fit;
%subplots layout
xyr=14.65/24.52*0.85; % A4, default size, no including margins
wd=height/width*xyr; %normalized width: screen width is one
NA=size(imps,2); % number of points
NF=ceil(NA/nppp);
% if NF >10
% ch=input(['There will be ',num2str(NF),' figures being created.\nIt is '...
% ,'recommended that you re-run:\n plotimp(imps,''Print'',true)\n'...
% ,'Are you sure to exit(y/n): '],'s');
% while ~strcmpi(ch,'y') && ~strcmpi(ch,'n')
% ch=input(['There will be ',num2str(NF),' figures being created.\nIt is '...
% ,'recommended that you re-run:\n plotimp(imps,''Print'',true)\n'...
% ,'Are you sure to exit(y/n): '],'s');
% end
% if strcmpi(ch,'y')
% return;
% end
% end
if isprint
subplotpos=zeros(1,4);
srcsz=get(0,'ScreenSize'); %get screen size
for k=1:nppp:NA
imp=imps(k:min(k+nppp-1,NA)); %segment
N=min(nppp,NA-k+1);
hf= figure('Position',srcsz,'visible',visibility);
ax=zeros(N,1);
if N>4
row=ceil(N/2);
for i=1:N
subplotpos(i,1)=(1-wd)*0.5+(1-mod(i,2))*0.5*wd; % x_start position
subplotpos(i,2)=0.05+0.95/row*(row-ceil(i/2));% y_start position
subplotpos(i,3)=0.44*wd; %width
subplotpos(i,4)=0.9/row; %height
subplot(row,2,i);
% subplot(gcf,'Position',subplotpos);
ax(i)=get(gcf,'CurrentAxes');
end
else % one column
row=N;
for i=1:N
subplotpos(i,1)=(1-wd)*0.5; % x_start position
subplotpos(i,2)=1/row*(row-i);% y_start position
subplotpos(i,3)=wd; %width
subplotpos(i,4)=1/row;
subplot(row,1,i);
ax(i)=get(gcf,'CurrentAxes');
end
end
for i=1:N
set(gcf,'CurrentAxes',ax(i)); hold on;
clegends=0; % legends counter
if iscmp
M=imp(i,1).meta.num;
else
M=1;
end
for j=1:M
if(isempty(imp(j,i).meta.rcvpos)==0) % valid point
clegends=clegends+1;
lenlimit=imp(j,i).para.length;
maxlen=min(lenlimit,len);
ys=phf*imp(j,i).g(1:maxlen);
ts=imp(j,i).ts(1:maxlen);
h(j)=plot(ts,ys,clr{j},'linewidth',1.5);
if ispeak
plot(ts(min(maxlen,imp(j,i).pn)),imp(j,i).apv,'or','MarkerFace','r');
end
if isfit
hold on;
plot(ts,imp(j,i).ag(1:maxlen));
hold off
end
y_lim_min=0;y_lim_max=0;
legend_(clegends)={[num2str(imp(j,i).meta.code(2)),'Hz']};
if(y_lim_min>min(ys))
y_lim_min=min(ys);
end
if(y_lim_max<max(ys))
y_lim_max=max(ys);
end
end
end
legend(legend_);
% title_=['Souce at ',...
% num2str(imp(1,i).meta.srcpos),'m and receiver at ',...
% num2str(imp(1,i).meta.rcvpos),'m'];
title_=['S: ',...
num2str(imp(1,i).meta.srcpos),'m, R: ',...
num2str(imp(1,i).meta.rcvpos),'m'];
x_lim=[-10,maxlen]/fs;
y_lim=[max(y_lim_min*1.1,-y_lim_max*0.1),y_lim_max*1.1+eps];%,'xTick',x_tick,...
set(gca,'Box','on','XScale',xscale,'xLim',...
x_lim,'yLim',y_lim,'YScale',yscale)
% 'yTick',y_tick,'yTickLabel',y_ticklabel);
% set(gca,'ticklength',2*get(gca,'ticklength'));
set(get(gca,'xLabel'),'String',xlabel,'FontSize',8,'FontWeight','normal');
set(get(gca,'yLabel'),'String',ylabel,'FontSize',8,'FontWeight','normal');
set(get(gca,'Title'),'String',title_,'FontSize',8,'FontWeight','normal');
set(ax(i),'OuterPosition',subplotpos(i,:),'FontSize',6);
set(ax(i),'YtickMode','manual');
set(ax(i),'YtickLabel',num2str(v2col(get(ax(i),'Ytick')),'%.2e'));
if exist('h','var')~=0
set(h,'LineWidth',0.6);
end
end
suptitle('THE EARTH IMPULSE CURVE');
fname=[num2str(offset+k),'-',num2str(offset+k+N-1)...
,'-',num2str(imp(1,1).meta.code(2)),...
'-',num2str(imp(1,1).meta.srcpos),'-',...
num2str(imp(1,1).meta.rcvpos),'-',...
num2str(imp(1,N).meta.rcvpos),'-',...
num2str(imp(1,1).meta.recnum)];
print_fig(fname,fmt,qual,hf);
close;
end
else % no print
srcsz=get(0,'ScreenSize'); %get screen size
for k=1:nppp:NA
imp=imps(k:min(k+nppp-1,NA)); %segment
N=min(nppp,NA-k+1);
hf= figure('Position',srcsz,'visible','on');
row=ceil(N/2);
for i=1:N
if N>1
subplot(row,2,i);
end
hold on;
clegends=0; % legends counter
if iscmp
M=imp(i,1).meta.num;
else
M=1;
end
for j=1:M
if(isempty(imp(j,i).meta.rcvpos)==0) % valid point
clegends=clegends+1;
lenlimit=imp(j,i).para.length;
maxlen=min(lenlimit,len);
ys=phf*imp(j,i).g(1:maxlen);
ts=imp(j,i).ts(1:maxlen);
h(j)=plot(ts,ys,clr{j});
if ispeak
plot(ts(min(maxlen,imp(j,i).pn)),imp(j,i).apv,'or','MarkerFace','r');
end
if isfit
hold on;
plot(ts,imp(j,i).ag(1:maxlen));
hold off
end
y_lim_min=0;y_lim_max=0;
legend_(clegends)={[num2str(imp(j,i).meta.code(2)),'Hz']};
if(y_lim_min>min(ys))
y_lim_min=min(ys);
end
if(y_lim_max<max(ys))
y_lim_max=max(ys);
end
end
end
legend(legend_);
% title_=['Souce at ',...
% num2str(imp(1,i).meta.srcpos),'m and receiver at ',...
% num2str(imp(1,i).meta.rcvpos),'m'];
title_=['Source at ',...
num2str(imp(1,i).meta.srcpos),'m, Receiver at ',...
num2str(imp(1,i).meta.rcvpos),'m'];
x_lim=[-10,maxlen]/fs;
y_lim=[max(y_lim_min*1.1,-y_lim_max*0.1),y_lim_max*1.1+eps];%,'xTick',x_tick,...
set(gca,'Box','on','XScale',xscale,'xLim',...
x_lim,'yLim',y_lim,'YScale',yscale)
% 'yTick',y_tick,'yTickLabel',y_ticklabel);
% set(gca,'ticklength',2*get(gca,'ticklength'));
set(get(gca,'xLabel'),'String',xlabel,'FontSize',12,'FontWeight','normal');
set(get(gca,'yLabel'),'String',ylabel,'FontSize',12,'FontWeight','normal');
set(get(gca,'Title'),'String',title_,'FontSize',12,'FontWeight','normal');
set(gca,'YtickMode','manual');
set(gca,'YtickLabel',num2str(v2col(get(gca,'Ytick')),'%.2e'),'FontWeight','bold');
if exist('h','var')~=0
set(h,'LineWidth',0.6);
end
end
% suptitle('THE EARTH IMPULSE CURVE');
end
end
% y_lim=[-0.1,1.1];y_tick=[0:0.2:1];
% y_ticklabel={'0';'0.2';'0.4';'0.6';'0.8';'1.0'};%;'1E+006';'1E+007''1E+000';
%x_lim=[1e-4,1]; x_tick=[0.1,1,10,100,1000]/1000;
%x_ticklabel={'10^{4}';'10^3';'10^-2';'10^-1';'1'};
% legend('512Hz','1024Hz','2048Hz','4096Hz');