Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/@mirenvelope/mirenvelope.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function varargout = mirenvelope(orig,varargin) | |
2 % e = mirenvelope(x) extracts the envelope of x, showing the global shape | |
3 % of the waveform. | |
4 % mirenvelope(...,m) specifies envelope extraction method. | |
5 % Possible values: | |
6 % m = 'Filter' uses a low-pass filtering. (Default strategy) | |
7 % m = 'Spectro' uses a spectrogram. | |
8 % | |
9 % Options related to the 'Filter' method: | |
10 % mirenvelope(...,'Hilbert'): performs a preliminary Hilbert | |
11 % transform. | |
12 % mirenvelope(...,'PreDecim',N) downsamples by a factor N>1, where | |
13 % N is an integer, before the low-pass filtering (Klapuri, 1999). | |
14 % Default value: N = 1. | |
15 % mirenvelope(...,'Filtertype',f) specifies the filter type. | |
16 % Possible values are: | |
17 % f = 'IIR': filter with one autoregressive coefficient | |
18 % (default) | |
19 % f = 'HalfHann': half-Hanning (raised cosine) filter | |
20 % (Scheirer, 1998) | |
21 % Option related to the 'IIR' option: | |
22 % mirenvelope(...,'Tau',t): time constant of low-pass filter in | |
23 % seconds. | |
24 % Default value: t = 0.02 s. | |
25 % mirenvelope(...,'PostDecim',N) downsamples by a factor N>1, where | |
26 % N is an integer, after the low-pass filtering. | |
27 % Default value: N = 16 if 'PreDecim' is not used, else N = 1. | |
28 % mirenvelope(...,'Trim'): trims the initial ascending phase of the | |
29 % curves related to the transitory state. | |
30 % | |
31 % Options related to the 'Spectro' method: | |
32 % mirenvelope(...,b) specifies whether the frequency range is further | |
33 % decomposed into bands. Possible values: | |
34 % b = 'Freq': no band decomposition (default value) | |
35 % b = 'Mel': Mel-band decomposition | |
36 % b = 'Bark': Bark-band decomposition | |
37 % b = 'Cents': decompositions into cents | |
38 % mirenvelope(...,'Frame',...) specifies the frame configuration. | |
39 % Default value: length: .1 s, hop factor: 10 %. | |
40 % mirenvelope(...,'UpSample',N) upsamples by a factor N>1, where | |
41 % N is an integer. | |
42 % Default value if 'UpSample' called: N = 2 | |
43 % mirenvelope(...,'Complex') toggles on the 'Complex' method for the | |
44 % spectral flux computation. | |
45 % | |
46 % Other available for all methods: | |
47 % mirenvelope(...,'Sampling',r): resamples to rate r (in Hz). | |
48 % 'Down' and 'Sampling' options cannot therefore be combined. | |
49 % mirenvelope(...,'Halfwave'): performs a half-wave rectification. | |
50 % mirenvelope(...,'Center'): centers the extracted envelope. | |
51 % mirenvelope(...,'HalfwaveCenter'): performs a half-wave | |
52 % rectification on the centered envelope. | |
53 % mirenvelope(...,'Log'): computes the common logarithm (base 10) of | |
54 % the envelope. | |
55 % mirenvelope(...,'Mu',mu): computes the logarithm of the | |
56 % envelope, before the eventual differentiation, using a mu-law | |
57 % compression (Klapuri, 2006). | |
58 % Default value for mu: 100 | |
59 % mirenvelope(...,'Log'): computes the logarithm of the envelope. | |
60 % mirenvelope(...,'Power'): computes the power (square) of the | |
61 % envelope. | |
62 % mirenvelope(...,'Diff'): computes the differentation of the | |
63 % envelope, i.e., the differences between successive samples. | |
64 % mirenvelope(...,'HalfwaveDiff'): performs a half-wave | |
65 % rectification on the differentiated envelope. | |
66 % mirenvelope(...,'Normal'): normalizes the values of the envelope by | |
67 % fixing the maximum value to 1. | |
68 % mirenvelope(...,'Lambda',l): sums the half-wave rectified envelope | |
69 % with the non-differentiated envelope, using the respective | |
70 % weight 0<l<1 and (1-l). (Klapuri et al., 2006) | |
71 % mirenvelope(...,'Smooth',o): smooths the envelope using a moving | |
72 % average of order o. | |
73 % Default value when the option is toggled on: o=30 | |
74 % mirenvelope(...,'Gauss',o): smooths the envelope using a gaussian | |
75 % of standard deviation o samples. | |
76 % Default value when the option is toggled on: o=30 | |
77 % mirenvelope(...,'Klapuri06'): follows the model proposed in | |
78 % (Klapuri et al., 2006). | |
79 | |
80 method.type = 'String'; | |
81 method.choice = {'Filter','Spectro'}; | |
82 method.default = 'Filter'; | |
83 option.method = method; | |
84 | |
85 %% options related to 'Filter': | |
86 | |
87 hilb.key = 'Hilbert'; | |
88 hilb.type = 'Boolean'; | |
89 hilb.default = 0; | |
90 option.hilb = hilb; | |
91 | |
92 decim.key = {'Decim','PreDecim'}; | |
93 decim.type = 'Integer'; | |
94 decim.default = 0; | |
95 option.decim = decim; | |
96 | |
97 filter.key = 'FilterType'; | |
98 filter.type = 'String'; | |
99 filter.choice = {'IIR','HalfHann',0}; | |
100 if isamir(orig,'mirenvelope') | |
101 filter.default = 0; % no more envelope extraction, already done | |
102 else | |
103 filter.default = 'IIR'; | |
104 end | |
105 option.filter = filter; | |
106 | |
107 %% options related to 'IIR': | |
108 tau.key = 'Tau'; | |
109 tau.type = 'Integer'; | |
110 tau.default = .02; | |
111 option.tau = tau; | |
112 | |
113 zp.key = 'ZeroPhase'; % internal use: for manual filtfilt | |
114 zp.type = 'Boolean'; | |
115 if isamir(orig,'mirenvelope') | |
116 zp.default = 0; | |
117 else | |
118 zp.default = NaN; | |
119 end | |
120 option.zp = zp; | |
121 | |
122 ds.key = {'Down','PostDecim'}; | |
123 ds.type = 'Integer'; | |
124 if isamir(orig,'mirenvelope') | |
125 ds.default = 1; | |
126 else | |
127 ds.default = NaN; % 0 if 'PreDecim' is used, else 16 | |
128 end | |
129 ds.when = 'After'; | |
130 ds.chunkcombine = 'During'; | |
131 option.ds = ds; | |
132 | |
133 trim.key = 'Trim'; | |
134 trim.type = 'Boolean'; | |
135 trim.default = 0; | |
136 trim.when = 'After'; | |
137 option.trim = trim; | |
138 | |
139 %% Options related to 'Spectro': | |
140 | |
141 band.type = 'String'; | |
142 band.choice = {'Freq','Mel','Bark','Cents'}; | |
143 band.default = 'Freq'; | |
144 option.band = band; | |
145 | |
146 up.key = {'UpSample'}; | |
147 up.type = 'Integer'; | |
148 up.default = 0; | |
149 up.keydefault = 2; | |
150 up.when = 'After'; | |
151 option.up = up; | |
152 | |
153 complex.key = 'Complex'; | |
154 complex.type = 'Boolean'; | |
155 complex.default = 0; | |
156 complex.when = 'After'; | |
157 option.complex = complex; | |
158 | |
159 %% Options related to all methods: | |
160 | |
161 sampling.key = 'Sampling'; | |
162 sampling.type = 'Integer'; | |
163 sampling.default = 0; | |
164 sampling.when = 'After'; | |
165 option.sampling = sampling; | |
166 | |
167 hwr.key = 'Halfwave'; | |
168 hwr.type = 'Boolean'; | |
169 hwr.default = 0; | |
170 hwr.when = 'After'; | |
171 option.hwr = hwr; | |
172 | |
173 c.key = 'Center'; | |
174 c.type = 'Boolean'; | |
175 c.default = 0; | |
176 c.when = 'After'; | |
177 option.c = c; | |
178 | |
179 chwr.key = 'HalfwaveCenter'; | |
180 chwr.type = 'Boolean'; | |
181 chwr.default = 0; | |
182 chwr.when = 'After'; | |
183 option.chwr = chwr; | |
184 | |
185 mu.key = 'Mu'; | |
186 mu.type = 'Integer'; | |
187 mu.default = 0; | |
188 mu.keydefault = 100; | |
189 mu.when = 'After'; | |
190 option.mu = mu; | |
191 | |
192 oplog.key = 'Log'; | |
193 oplog.type = 'Boolean'; | |
194 oplog.default = 0; | |
195 oplog.when = 'After'; | |
196 option.log = oplog; | |
197 | |
198 oppow.key = 'Power'; | |
199 oppow.type = 'Integer'; | |
200 oppow.default = 0; | |
201 oppow.when = 'After'; | |
202 option.power = oppow; | |
203 | |
204 diff.key = 'Diff'; | |
205 diff.type = 'Integer'; | |
206 diff.default = 0; | |
207 diff.keydefault = 1; | |
208 diff.when = 'After'; | |
209 option.diff = diff; | |
210 | |
211 diffhwr.key = 'HalfwaveDiff'; | |
212 diffhwr.type = 'Integer'; | |
213 diffhwr.default = 0; | |
214 diffhwr.keydefault = 1; | |
215 diffhwr.when = 'After'; | |
216 option.diffhwr = diffhwr; | |
217 | |
218 lambda.key = 'Lambda'; | |
219 lambda.type = 'Integer'; | |
220 lambda.default = 1; | |
221 lambda.when = 'After'; | |
222 option.lambda = lambda; | |
223 | |
224 aver.key = 'Smooth'; | |
225 aver.type = 'Integer'; | |
226 aver.default = 0; | |
227 aver.keydefault = 30; | |
228 aver.when = 'After'; | |
229 option.aver = aver; | |
230 | |
231 gauss.key = 'Gauss'; | |
232 gauss.type = 'Integer'; | |
233 gauss.default = 0; | |
234 gauss.keydefault = 30; | |
235 gauss.when = 'After'; | |
236 option.gauss = gauss; | |
237 | |
238 norm.key = 'Normal'; | |
239 norm.type = 'Boolean'; | |
240 norm.default = 0; | |
241 norm.when = 'After'; | |
242 option.norm = norm; | |
243 | |
244 presel.type = 'String'; | |
245 presel.choice = {'Klapuri06'}; | |
246 presel.default = 0; | |
247 option.presel = presel; | |
248 | |
249 frame.key = 'Frame'; | |
250 frame.type = 'Integer'; | |
251 frame.number = 2; | |
252 frame.default = [.1 .1]; | |
253 option.frame = frame; | |
254 | |
255 specif.option = option; | |
256 | |
257 specif.eachchunk = 'Normal'; | |
258 specif.combinechunk = 'Concat'; | |
259 specif.extensive = 1; | |
260 | |
261 varargout = mirfunction(@mirenvelope,orig,varargin,nargout,specif,@init,@main); | |
262 | |
263 | |
264 function [x type] = init(x,option) | |
265 type = 'mirenvelope'; | |
266 if isamir(x,'mirscalar') | |
267 return | |
268 end | |
269 if ischar(option.presel) && strcmpi(option.presel,'Klapuri06') | |
270 option.method = 'Spectro'; | |
271 end | |
272 if not(isamir(x,'mirenvelope')) | |
273 if strcmpi(option.method,'Filter') | |
274 if isnan(option.zp) | |
275 if strcmpi(option.filter,'IIR') | |
276 option.zp = 1; | |
277 else | |
278 option.zp = 0; | |
279 end | |
280 end | |
281 if option.zp == 1 | |
282 x = mirenvelope(x,'ZeroPhase',2,'Down',1,... | |
283 'Tau',option.tau,'PreDecim',option.decim); | |
284 end | |
285 elseif strcmpi(option.method,'Spectro') | |
286 x = mirspectrum(x,'Frame',option.frame.length.val,... | |
287 option.frame.length.unit,... | |
288 option.frame.hop.val,... | |
289 option.frame.hop.unit,... | |
290 'Window','hanning',... | |
291 option.band,'Power'); | |
292 | |
293 end | |
294 end | |
295 | |
296 | |
297 function e = main(orig,option,postoption) | |
298 if iscell(orig) | |
299 orig = orig{1}; | |
300 end | |
301 if isamir(orig,'mirscalar') | |
302 d = get(orig,'Data'); | |
303 fp = get(orig,'FramePos'); | |
304 for i = 1:length(d) | |
305 for j = 1:length(d{i}) | |
306 d{i}{j} = reshape(d{i}{j},size(d{i}{j},2),1,size(d{i}{j},3)); | |
307 p{i}{j} = mean(fp{i}{j})'; | |
308 end | |
309 end | |
310 e.downsampl = 0; | |
311 e.hwr = 0; | |
312 e.diff = 0; | |
313 e.method = 'Spectro'; | |
314 e.phase = {{}}; | |
315 e = class(e,'mirenvelope',mirtemporal(orig)); | |
316 e = set(e,'Title','Envelope','Data',d,'Pos',p,'FramePos',{{}}); | |
317 postoption.trim = 0; | |
318 postoption.ds = 0; | |
319 e = post(e,postoption); | |
320 return | |
321 end | |
322 if isfield(option,'presel') && ischar(option.presel) && ... | |
323 strcmpi(option.presel,'Klapuri06') | |
324 option.method = 'Spectro'; | |
325 postoption.up = 2; | |
326 postoption.mu = 100; | |
327 postoption.diffhwr = 1; | |
328 postoption.lambda = .8; | |
329 end | |
330 if isfield(postoption,'ds') && isnan(postoption.ds) | |
331 if option.decim | |
332 postoption.ds = 0; | |
333 else | |
334 postoption.ds = 16; | |
335 end | |
336 end | |
337 if not(isfield(option,'filter')) || not(ischar(option.filter)) | |
338 e = post(orig,postoption); | |
339 elseif strcmpi(option.method,'Spectro') | |
340 d = get(orig,'Data'); | |
341 fp = get(orig,'FramePos'); | |
342 sr = get(orig,'Sampling'); | |
343 ch = get(orig,'Channels'); | |
344 ph = get(orig,'Phase'); | |
345 for h = 1:length(d) | |
346 sr{h} = 0; | |
347 for i = 1:length(d{h}) | |
348 if size(d{h}{i},3)>1 % Already in bands (channels in 3d dim) | |
349 d{h}{i} = permute(sum(d{h}{i}),[2 1 3]); | |
350 ph{h}{i} = permute(ph{h}{i},[2 1 3]); | |
351 else % Simple spectrogram, frequency range sent to 3d dim | |
352 d{h}{i} = permute(d{h}{i},[2 3 1]); | |
353 ph{h}{i} = permute(ph{h}{i},[2 3 1]); | |
354 end | |
355 p{h}{i} = mean(fp{h}{i})'; | |
356 if not(sr{h}) && size(fp{h}{i},2)>1 | |
357 sr{h} = 1/(fp{h}{i}(1,2)-fp{h}{i}(1,1)); | |
358 end | |
359 end | |
360 if not(sr{h}) | |
361 warning('WARNING IN MIRENVELOPE: The frame decomposition did not succeed. Either the input is of too short duration, or the chunk size is too low.'); | |
362 end | |
363 ch{h} = (1:size(d{h}{1},3))'; | |
364 end | |
365 e.downsampl = 0; | |
366 e.hwr = 0; | |
367 e.diff = 0; | |
368 %e.todelete = {}; | |
369 e.method = 'Spectro'; | |
370 e.phase = ph; | |
371 e = class(e,'mirenvelope',mirtemporal(orig)); | |
372 e = set(e,'Title','Envelope','Data',d,'Pos',p,... | |
373 'Sampling',sr,'Channels',ch); | |
374 postoption.trim = 0; | |
375 postoption.ds = 0; | |
376 e = post(e,postoption); | |
377 else | |
378 if isnan(option.zp) | |
379 if strcmpi(option.filter,'IIR') | |
380 option.zp = 1; | |
381 else | |
382 option.zp = 0; | |
383 end | |
384 end | |
385 if option.zp == 1 | |
386 option.decim = 0; | |
387 end | |
388 e.downsampl = 1; | |
389 e.hwr = 0; | |
390 e.diff = 0; | |
391 e.method = option.filter; | |
392 e.phase = {}; | |
393 e = class(e,'mirenvelope',mirtemporal(orig)); | |
394 e = purgedata(e); | |
395 e = set(e,'Title','Envelope'); | |
396 sig = get(e,'Data'); | |
397 x = get(e,'Pos'); | |
398 sr = get(e,'Sampling'); | |
399 disp('Extracting envelope...') | |
400 d = cell(1,length(sig)); | |
401 [state e] = gettmp(orig,e); | |
402 for k = 1:length(sig) | |
403 if option.decim | |
404 sr{k} = sr{k}/option.decim; | |
405 end | |
406 if strcmpi(option.filter,'IIR') | |
407 a2 = exp(-1/(option.tau*sr{k})); % filter coefficient | |
408 a = [1 -a2]; | |
409 b = 1-a2; | |
410 elseif strcmpi(option.filter,'HalfHann') | |
411 a = 1; | |
412 b = hann(sr{k}*.4); | |
413 b = b(ceil(length(b)/2):end); | |
414 end | |
415 d{k} = cell(1,length(sig{k})); | |
416 for i = 1:length(sig{k}) | |
417 sigi = sig{k}{i}; | |
418 if option.zp == 2 | |
419 sigi = flipdim(sigi,1); | |
420 end | |
421 if option.hilb | |
422 try | |
423 for h = 1:size(sigi,2) | |
424 for j = 1:size(sigi,3) | |
425 sigi(:,h,j) = hilbert(sigi(:,h,j)); | |
426 end | |
427 end | |
428 catch | |
429 disp('Signal Processing Toolbox does not seem to be installed. No Hilbert transform.'); | |
430 end | |
431 end | |
432 sigi = abs(sigi); | |
433 | |
434 if option.decim | |
435 dsigi = zeros(ceil(size(sigi,1)/option.decim),... | |
436 size(sigi,2),size(sigi,3)); | |
437 for f = 1:size(sigi,2) | |
438 for c = 1:size(sigi,3) | |
439 dsigi(:,f,c) = decimate(sigi(:,f,c),option.decim); | |
440 end | |
441 end | |
442 sigi = dsigi; | |
443 clear dsigi | |
444 x{k}{i} = x{k}{i}(1:option.decim:end,:,:); | |
445 end | |
446 | |
447 % tmp = filtfilt(1-a,[1 -a],sigi); % zero-phase IIR filter for smoothing the envelope | |
448 | |
449 % Manual filtfilt | |
450 emptystate = isempty(state); | |
451 tmp = zeros(size(sigi)); | |
452 for c = 1:size(sigi,3) | |
453 if emptystate | |
454 [tmp(:,:,c) state(:,c,1)] = filter(b,a,sigi(:,:,c)); | |
455 else | |
456 [tmp(:,:,c) state(:,c,1)] = filter(b,a,sigi(:,:,c),... | |
457 state(:,c,1)); | |
458 end | |
459 end | |
460 | |
461 tmp = max(tmp,0); % For security reason... | |
462 if option.zp == 2 | |
463 tmp = flipdim(tmp,1); | |
464 end | |
465 d{k}{i} = tmp; | |
466 %td{k} = round(option.tau*sr{k}*1.5); | |
467 end | |
468 end | |
469 e = set(e,'Data',d,'Pos',x,'Sampling',sr); %,'ToDelete',td | |
470 e = settmp(e,state); | |
471 if not(option.zp == 2) | |
472 e = post(e,postoption); | |
473 end | |
474 end | |
475 if isfield(option,'presel') && ischar(option.presel) && ... | |
476 strcmpi(option.presel,'Klapuri06') | |
477 e = mirsum(e,'Adjacent',10); | |
478 end | |
479 | |
480 | |
481 function e = post(e,postoption) | |
482 if isempty(postoption) | |
483 return | |
484 end | |
485 if isfield(postoption,'lambda') && not(postoption.lambda) | |
486 postoption.lambda = 1; | |
487 end | |
488 d = get(e,'Data'); | |
489 tp = get(e,'Time'); | |
490 sr = get(e,'Sampling'); | |
491 ds = get(e,'DownSampling'); | |
492 ph = get(e,'Phase'); | |
493 for k = 1:length(d) | |
494 if isfield(postoption,'sampling') | |
495 if postoption.sampling | |
496 newsr = postoption.sampling; | |
497 elseif isfield(postoption,'ds') && postoption.ds>1 | |
498 newsr = sr{k}/postoption.ds; | |
499 else | |
500 newsr = sr{k}; | |
501 end | |
502 end | |
503 if isfield(postoption,'up') && postoption.up | |
504 [z,p,gain] = butter(6,10/newsr/postoption.up*2,'low'); | |
505 [sos,g] = zp2sos(z,p,gain); | |
506 Hd = dfilt.df2tsos(sos,g); | |
507 end | |
508 for i = 1:length(d{k}) | |
509 if isfield(postoption,'sampling') && postoption.sampling | |
510 if and(sr{k}, not(sr{k} == postoption.sampling)) | |
511 dk = d{k}{i}; | |
512 for j = 1:size(dk,3) | |
513 if not(sr{k} == round(sr{k})) | |
514 mirerror('mirenvelope','The ''Sampling'' postoption cannot be used after using the ''Down'' postoption.'); | |
515 end | |
516 rk(:,:,j) = resample(dk(:,:,j),postoption.sampling,sr{k}); | |
517 end | |
518 d{k}{i} = rk; | |
519 tp{k}{i} = repmat((0:size(d{k}{i},1)-1)',... | |
520 [1 1 size(tp{k}{i},3)])... | |
521 /postoption.sampling + tp{k}{i}(1,:,:); | |
522 if not(iscell(ds)) | |
523 ds = cell(length(d)); | |
524 end | |
525 ds{k} = round(sr{k}/postoption.sampling); | |
526 end | |
527 elseif isfield(postoption,'ds') && postoption.ds>1 | |
528 if not(postoption.ds == round(postoption.ds)) | |
529 mirerror('mirenvelope','The ''Down'' sampling rate should be an integer.'); | |
530 end | |
531 ds = postoption.ds; | |
532 tp{k}{i} = tp{k}{i}(1:ds:end,:,:); % Downsampling... | |
533 d{k}{i} = d{k}{i}(1:ds:end,:,:); | |
534 end | |
535 if isfield(postoption,'sampling') | |
536 if not(strcmpi(e.method,'Spectro')) && postoption.trim | |
537 tdk = round(newsr*.1); | |
538 d{k}{i}(1:tdk,:,:) = repmat(d{k}{i}(tdk,:,:),[tdk,1,1]); | |
539 d{k}{i}(end-tdk+1:end,:,:) = repmat(d{k}{i}(end-tdk,:,:),[tdk,1,1]); | |
540 end | |
541 if postoption.log | |
542 d{k}{i} = log10(d{k}{i}); | |
543 end | |
544 if postoption.mu | |
545 dki = max(0,d{k}{i}); | |
546 mu = postoption.mu; | |
547 dki = log(1+mu*dki)/log(1+mu); | |
548 dki(~isfinite(d{k}{i})) = NaN; | |
549 d{k}{i} = dki; | |
550 end | |
551 if postoption.power | |
552 d{k}{i} = d{k}{i}.^2; | |
553 end | |
554 if postoption.up | |
555 dki = zeros(size(d{k}{i},1).*postoption.up,... | |
556 size(d{k}{i},2),size(d{k}{i},3)); | |
557 dki(1:postoption.up:end,:,:) = d{k}{i}; | |
558 dki = filter(Hd,[dki;... | |
559 zeros(6,size(d{k}{i},2),size(d{k}{i},3))]); | |
560 d{k}{i} = dki(1+ceil(6/2):end-floor(6/2),:,:); | |
561 tki = zeros(size(tp{k}{i},1).*postoption.up,... | |
562 size(tp{k}{i},2),... | |
563 size(tp{k}{i},3)); | |
564 dt = repmat((tp{k}{i}(2)-tp{k}{i}(1))... | |
565 /postoption.up,... | |
566 [size(tp{k}{i},1),1,1]); | |
567 for j = 1:postoption.up | |
568 tki(j:postoption.up:end,:,:) = tp{k}{i}+dt*(j-1); | |
569 end | |
570 tp{k}{i} = tki; | |
571 newsr = sr{k}*postoption.up; | |
572 end | |
573 if (postoption.diffhwr || postoption.diff) && ... | |
574 not(get(e,'Diff')) | |
575 tp{k}{i} = tp{k}{i}(1:end-1,:,:); | |
576 order = max(postoption.diffhwr,postoption.diff); | |
577 if postoption.complex | |
578 dph = diff(ph{k}{i},2); | |
579 dph = dph/(2*pi);% - round(dph/(2*pi)); | |
580 ddki = sqrt(d{k}{i}(3:end,:,:).^2 + d{k}{i}(2:end-1,:,:).^2 ... | |
581 - 2.*d{k}{i}(3:end,:,:)... | |
582 .*d{k}{i}(2:end-1,:,:)... | |
583 .*cos(dph)); | |
584 d{k}{i} = d{k}{i}(2:end,:,:); | |
585 tp{k}{i} = tp{k}{i}(2:end,:,:); | |
586 elseif order == 1 | |
587 ddki = diff(d{k}{i},1,1); | |
588 else | |
589 b = firls(order,[0 0.9],[0 0.9*pi],'differentiator'); | |
590 ddki = filter(b,1,... | |
591 [repmat(d{k}{i}(1,:,:),[order,1,1]);... | |
592 d{k}{i};... | |
593 repmat(d{k}{i}(end,:,:),[order,1,1])]); | |
594 ddki = ddki(order+1:end-order-1,:,:); | |
595 end | |
596 if postoption.diffhwr | |
597 ddki = hwr(ddki); | |
598 end | |
599 d{k}{i} = (1-postoption.lambda)*d{k}{i}(1:end-1,:,:)... | |
600 + postoption.lambda*sr{k}/10*ddki; | |
601 end | |
602 if postoption.aver | |
603 y = filter(ones(1,postoption.aver),1,... | |
604 [d{k}{i};zeros(postoption.aver,... | |
605 size(d{k}{i},2),... | |
606 size(d{k}{i},3))]); | |
607 d{k}{i} = y(1+ceil(postoption.aver/2):... | |
608 end-floor(postoption.aver/2),:,:); | |
609 end | |
610 if postoption.gauss | |
611 sigma = postoption.gauss; | |
612 gauss = 1/sigma/2/pi... | |
613 *exp(- (-4*sigma:4*sigma).^2 /2/sigma^2); | |
614 y = filter(gauss,1,[d{k}{i};zeros(4*sigma,1,size(d{k}{i},3))]); | |
615 y = y(4*sigma:end,:,:); | |
616 d{k}{i} = y(1:size(d{k}{i},1),:,:); | |
617 end | |
618 if postoption.chwr | |
619 d{k}{i} = center(d{k}{i}); | |
620 d{k}{i} = hwr(d{k}{i}); | |
621 end | |
622 if postoption.hwr | |
623 d{k}{i} = hwr(d{k}{i}); | |
624 end | |
625 if postoption.c | |
626 d{k}{i} = center(d{k}{i}); | |
627 end | |
628 if postoption.norm | |
629 d{k}{i} = d{k}{i}./repmat(max(abs(d{k}{i})),... | |
630 [size(d{k}{i},1),1,1]); | |
631 end | |
632 end | |
633 end | |
634 if isfield(postoption,'sampling') | |
635 sr{k} = newsr; | |
636 end | |
637 end | |
638 if isfield(postoption,'ds') && postoption.ds>1 | |
639 e = set(e,'DownSampling',postoption.ds,'Sampling',sr); | |
640 elseif isfield(postoption,'sampling') && postoption.sampling | |
641 e = set(e,'DownSampling',ds,'Sampling',sr); | |
642 elseif isfield(postoption,'up') && postoption.up | |
643 e = set(e,'Sampling',sr); | |
644 end | |
645 if isfield(postoption,'sampling') | |
646 if postoption.hwr | |
647 e = set(e,'Halfwave',1); | |
648 end | |
649 if postoption.diff | |
650 e = set(e,'Diff',1,'Halfwave',0,'Title','Differentiated envelope'); | |
651 end | |
652 if postoption.diffhwr | |
653 e = set(e,'Diff',1,'Halfwave',1,'Centered',0); | |
654 end | |
655 if postoption.c | |
656 e = set(e,'Centered',1); | |
657 end | |
658 if postoption.chwr | |
659 e = set(e,'Halfwave',1,'Centered',1); | |
660 end | |
661 end | |
662 e = set(e,'Data',d,'Time',tp); | |
663 %if isfield(postoption,'frame') && isstruct(postoption.frame) | |
664 % e = mirframenow(e,postoption); | |
665 %end |