Daniel@0: function varargout = mirautocor(orig,varargin) Daniel@0: % a = mirautocor(x) computes the autocorrelation function related to x. Daniel@0: % Optional parameters: Daniel@0: % mirautocor(...,'Min',mi) indicates the lowest delay taken into Daniel@0: % consideration. The unit can be precised: Daniel@0: % mirautocor(...,'Min',mi,'s') (default unit) Daniel@0: % mirautocor(...,'Min',mi,'Hz') Daniel@0: % Default value: 0 s. Daniel@0: % mirautocor(...,'Max',ma) indicates the highest delay taken into Daniel@0: % consideration. The unit can be specified as for 'Min'. Daniel@0: % Default value: Daniel@0: % if x is a signal, the highest delay is 0.05 s Daniel@0: % (corresponding to a minimum frequency of 20 Hz). Daniel@0: % if x is an envelope, the highest delay is 2 s. Daniel@0: % mirautocor(...,'Resonance',r) multiplies the autocorrelation function Daniel@0: % with a resonance curve: Daniel@0: % Possible values: Daniel@0: % 'Toiviainen' from (Toiviainen & Snyder, 2003) Daniel@0: % 'vanNoorden' from (van Noorden & Moelants, 2001) Daniel@0: % mirautocor(...,'Center',c) assigns the center value of the Daniel@0: % resonance curve, in seconds. Daniel@0: % Works mainly with 'Toiviainen' option. Daniel@0: % Default value: c = 0.5 Daniel@0: % mirautocor(...,'Enhanced',a) reduces the effect of subharmonics. Daniel@0: % The original autocorrelation function is half-wave rectified, Daniel@0: % time-scaled by the factor a (which can be a factor list as Daniel@0: % well), and substracted from the original clipped function. Daniel@0: % (Tolonen & Karjalainen) Daniel@0: % If the 'Enhanced' option is not followed by any value, Daniel@0: % default value is a = 2:10 Daniel@0: % mirautocor(...,'Halfwave') performs a half-wave rectification on the Daniel@0: % result. Daniel@0: % mirautocor(...,'Freq') represents the autocorrelation function in the Daniel@0: % frequency domain. Daniel@0: % mirautocor(...,'NormalWindow',w): applies a window to the input Daniel@0: % signal and divides the autocorrelation by the autocorrelation of Daniel@0: % that window (Boersma 1993). Daniel@0: % Possible values: any windowing function proposed in the Signal Daniel@0: % Processing Toolbox (help window) plus 'rectangle' (no Daniel@0: % windowing) Daniel@0: % Default value: w = 'hanning' Daniel@0: % mirautocor(...,'NormalWindow',0): toggles off this normalization Daniel@0: % (which is on by default). Daniel@0: % All the parameters described previously can be applied to an Daniel@0: % autocorrelation function itself, in order to arrange the results Daniel@0: % after the actual computation of the autocorrelation computations. Daniel@0: % For instance: a = mirautocor(a,'Resonance','Enhanced') Daniel@0: % Other optional parameter: Daniel@0: % mirautocor(...,'Compres',k) computes the autocorrelation in the Daniel@0: % frequency domain and includes a magnitude compression of the Daniel@0: % spectral representation. A normal autocorrelation corresponds Daniel@0: % to the value k=2, but values lower than 2 are suggested by Daniel@0: % (Tolonen & Karjalainen, 2000). Daniel@0: % Default value: k = 0.67 Daniel@0: % mirautocor(...,'Normal',n) or simply mirautocor(...,n) specifies Daniel@0: % the normalization strategy. Accepted values are 'biased', Daniel@0: % 'unbiased', 'coeff' (default value) and 'none'. Daniel@0: % See help xcorr for an explanation. Daniel@0: Daniel@0: min.key = 'Min'; Daniel@0: min.type = 'Integer'; Daniel@0: min.unit = {'s','Hz'}; Daniel@0: if isamir(orig,'mirspectrum') Daniel@0: min.defaultunit = 'Hz'; Daniel@0: else Daniel@0: min.defaultunit = 's'; Daniel@0: end Daniel@0: min.default = 0; Daniel@0: min.opposite = 'max'; Daniel@0: option.min = min; Daniel@0: Daniel@0: max.key = 'Max'; Daniel@0: max.type = 'Integer'; Daniel@0: max.unit = {'s','Hz'}; Daniel@0: if isamir(orig,'mirspectrum') Daniel@0: max.defaultunit = 'Hz'; Daniel@0: else Daniel@0: max.defaultunit = 's'; Daniel@0: end Daniel@0: if isamir(orig,'mirenvelope') || isamir(orig,'mirdiffenvelope') Daniel@0: max.default = 2; % for envelopes, longest period: 2 seconds. Daniel@0: elseif isamir(orig,'miraudio') || ischar(orig) % for audio signal,lowest frequency: 20 Hz. Daniel@0: max.default = 1/20; Daniel@0: else Daniel@0: max.default = Inf; Daniel@0: end Daniel@0: max.opposite = 'min'; Daniel@0: option.max = max; Daniel@0: Daniel@0: scaleoptbw.key = 'Normal'; %'Normal' keyword optional Daniel@0: scaleoptbw.key = 'Boolean'; Daniel@0: option.scaleoptbw = scaleoptbw; Daniel@0: scaleopt.type = 'String'; Daniel@0: scaleopt.choice = {'biased','unbiased','coeff','none'}; Daniel@0: scaleopt.default = 'coeff'; Daniel@0: option.scaleopt = scaleopt; Daniel@0: Daniel@0: gener.key = {'Generalized','Compres'}; Daniel@0: gener.type = 'Integer'; Daniel@0: gener.default = 2; Daniel@0: gener.keydefault = .67; Daniel@0: option.gener = gener; Daniel@0: Daniel@0: ni.key = 'NormalInput'; %% Normalize before frame or chunk?? Daniel@0: ni.type = 'Boolean'; Daniel@0: ni.default = 0; Daniel@0: option.ni = ni; Daniel@0: Daniel@0: reso.key = 'Resonance'; Daniel@0: reso.type = 'String'; Daniel@0: reso.choice = {'ToiviainenSnyder','Toiviainen','vanNoorden','no','off',0}; Daniel@0: reso.keydefault = 'Toiviainen'; Daniel@0: reso.when = 'After'; Daniel@0: reso.default = 0; Daniel@0: option.reso = reso; Daniel@0: Daniel@0: resocenter.key = {'Center','Centre'}; Daniel@0: resocenter.type = 'Integer'; Daniel@0: resocenter.when = 'After'; Daniel@0: option.resocenter = resocenter; Daniel@0: Daniel@0: h.key = 'Halfwave'; Daniel@0: h.type = 'Boolean'; Daniel@0: h.when = 'After'; Daniel@0: h.default = 0; Daniel@0: option.h = h; Daniel@0: Daniel@0: e.key = 'Enhanced'; Daniel@0: e.type = 'Integers'; Daniel@0: e.default = []; Daniel@0: e.keydefault = 2:10; Daniel@0: e.when = 'After'; Daniel@0: option.e = e; Daniel@0: Daniel@0: fr.key = 'Freq'; Daniel@0: fr.type = 'Boolean'; Daniel@0: fr.default = 0; Daniel@0: fr.when = 'After'; Daniel@0: option.fr = fr; Daniel@0: Daniel@0: nw.key = 'NormalWindow'; Daniel@0: nw.when = 'Both'; Daniel@0: if isamir(orig,'mirspectrum') Daniel@0: nw.default = 0; Daniel@0: elseif isamir(orig,'mirenvelope') Daniel@0: nw.default = 'rectangular'; Daniel@0: else Daniel@0: nw.default = 'hanning'; Daniel@0: end Daniel@0: option.nw = nw; Daniel@0: Daniel@0: win.key = 'Window'; Daniel@0: win.type = 'String'; Daniel@0: win.default = NaN; Daniel@0: option.win = win; Daniel@0: Daniel@0: specif.option = option; Daniel@0: Daniel@0: specif.defaultframelength = 0.05; Daniel@0: specif.defaultframehop = 0.5; Daniel@0: specif.eachchunk = @eachchunk; Daniel@0: specif.combinechunk = @combinechunk; Daniel@0: Daniel@0: if isamir(orig,'mirscalar') || isamir(orig,'mirenvelope') Daniel@0: specif.nochunk = 1; Daniel@0: end Daniel@0: Daniel@0: varargout = mirfunction(@mirautocor,orig,varargin,nargout,specif,@init,@main); Daniel@0: Daniel@0: Daniel@0: function [x type] = init(x,option) Daniel@0: type = 'mirautocor'; Daniel@0: Daniel@0: Daniel@0: function a = main(orig,option,postoption) Daniel@0: if iscell(orig) Daniel@0: orig = orig{1}; Daniel@0: end Daniel@0: if isa(orig,'mirautocor') Daniel@0: a = orig; Daniel@0: if not(isempty(option)) && ... Daniel@0: (option.min || iscell(option.max) || option.max < Inf) Daniel@0: coeff = get(a,'Coeff'); Daniel@0: delay = get(a,'Delay'); Daniel@0: for h = 1:length(coeff) Daniel@0: if a.freq Daniel@0: mi = 1/option.max; Daniel@0: ma = 1/option.min; Daniel@0: else Daniel@0: mi = option.min; Daniel@0: ma = option.max; Daniel@0: end Daniel@0: for k = 1:length(coeff{h}) Daniel@0: range = find(and(delay{h}{k}(:,1,1) >= mi,... Daniel@0: delay{h}{k}(:,1,1) <= ma)); Daniel@0: coeff{h}{k} = coeff{h}{k}(range,:,:); Daniel@0: delay{h}{k} = delay{h}{k}(range,:,:); Daniel@0: end Daniel@0: end Daniel@0: a = set(a,'Coeff',coeff,'Delay',delay); Daniel@0: end Daniel@0: if not(isempty(postoption)) && not(isequal(postoption,0)) Daniel@0: a = post(a,postoption); Daniel@0: end Daniel@0: elseif ischar(orig) Daniel@0: a = mirautocor(miraudio(orig),option,postoption); Daniel@0: else Daniel@0: if nargin == 0 Daniel@0: orig = []; Daniel@0: end Daniel@0: a.freq = 0; Daniel@0: a.ofspectrum = 0; Daniel@0: a.window = {}; Daniel@0: a.normalwindow = 0; Daniel@0: a = class(a,'mirautocor',mirdata(orig)); Daniel@0: a = purgedata(a); Daniel@0: a = set(a,'Ord','coefficients'); Daniel@0: sig = get(orig,'Data'); Daniel@0: if isa(orig,'mirspectrum') Daniel@0: a = set(a,'Title','Spectrum autocorrelation','OfSpectrum',1,... Daniel@0: 'Abs','frequency (Hz)'); Daniel@0: pos = get(orig,'Pos'); Daniel@0: else Daniel@0: if isa(orig,'mirscalar') Daniel@0: a = set(a,'Title',[get(orig,'Title') ' autocorrelation']); Daniel@0: pos = get(orig,'FramePos'); Daniel@0: for k = 1:length(sig) Daniel@0: for l = 1:length(sig{k}) Daniel@0: sig{k}{l} = sig{k}{l}'; Daniel@0: pos{k}{l} = pos{k}{l}(1,:,:)'; Daniel@0: end Daniel@0: end Daniel@0: else Daniel@0: if isa(orig,'mirenvelope') Daniel@0: a = set(a,'Title','Envelope autocorrelation'); Daniel@0: elseif not(isa(orig,'mirautocor')) Daniel@0: a = set(a,'Title','Waveform autocorrelation'); Daniel@0: end Daniel@0: pos = get(orig,'Pos'); Daniel@0: end Daniel@0: a = set(a,'Abs','lag (s)'); Daniel@0: end Daniel@0: f = get(orig,'Sampling'); Daniel@0: Daniel@0: if isnan(option.win) Daniel@0: if isequal(option.nw,0) || ... Daniel@0: strcmpi(option.nw,'Off') || strcmpi(option.nw,'No') Daniel@0: option.win = 0; Daniel@0: elseif isequal(option.nw,1) || strcmpi(option.nw,'On') || ... Daniel@0: strcmpi(option.nw,'Yes') Daniel@0: option.win = 'hanning'; Daniel@0: else Daniel@0: option.win = postoption.nw; Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: coeff = cell(1,length(sig)); Daniel@0: lags = cell(1,length(sig)); Daniel@0: wind = cell(1,length(sig)); Daniel@0: for k = 1:length(sig) Daniel@0: s = sig{k}; Daniel@0: p = pos{k}; Daniel@0: fk = f{k}; Daniel@0: if iscell(option.max) Daniel@0: mi = option.min{k}; Daniel@0: ma = option.max{k}; Daniel@0: else Daniel@0: mi = option.min; Daniel@0: ma = option.max; Daniel@0: end Daniel@0: coeffk = cell(1,length(s)); Daniel@0: lagsk = cell(1,length(s)); Daniel@0: windk = cell(1,length(s)); Daniel@0: for l = 1:length(s) Daniel@0: sl = s{l}; Daniel@0: sl(isnan(sl)) = 0; Daniel@0: if option.ni Daniel@0: mxsl = repmat(max(sl),[size(sl,1),1,1]); Daniel@0: mnsl = repmat(min(sl),[size(sl,1),1,1]); Daniel@0: sl = (sl-mnsl)./(mxsl-mnsl); Daniel@0: end Daniel@0: pl = p{l}; Daniel@0: pl = pl-repmat(pl(1,:,:),[size(pl,1),1,1]); Daniel@0: ls = size(sl,1); Daniel@0: if mi Daniel@0: misp = find(pl(:,1,1)>=mi); Daniel@0: if isempty(misp) Daniel@0: warning('WARNING IN MIRAUTOCOR: The specified range of delays exceeds the temporal length of the signal.'); Daniel@0: disp('Minimum delay set to zero.') Daniel@0: misp = 1; % misp is the lowest index of the lag range Daniel@0: mi = 0; Daniel@0: else Daniel@0: misp = misp(1); Daniel@0: end Daniel@0: else Daniel@0: misp = 1; Daniel@0: end Daniel@0: if ma Daniel@0: masp = find(pl(:,1,1)>=ma); Daniel@0: if isempty(masp) Daniel@0: masp = Inf; Daniel@0: else Daniel@0: masp = masp(1); Daniel@0: end Daniel@0: else Daniel@0: masp = Inf; Daniel@0: end Daniel@0: masp = min(masp,ceil(ls/2)); Daniel@0: if masp <= misp Daniel@0: if size(sl,2) > 1 Daniel@0: warning('WARNING IN MIRAUTOCOR: Frame length is too small.'); Daniel@0: else Daniel@0: warning('WARNING IN MIRAUTOCOR: The audio sequence is too small.'); Daniel@0: end Daniel@0: display('The autocorrelation is not defined for this range of delays.'); Daniel@0: end Daniel@0: sl = center(sl); Daniel@0: if not(ischar(option.win)) || strcmpi(option.win,'Rectangular') Daniel@0: kw = ones(size(sl)); Daniel@0: else Daniel@0: N = size(sl,1); Daniel@0: winf = str2func(option.win); Daniel@0: try Daniel@0: w = window(winf,N); Daniel@0: catch Daniel@0: if strcmpi(option.win,'hamming') Daniel@0: disp('Signal Processing Toolbox does not seem to be installed. Recompute the hamming window manually.'); Daniel@0: w = 0.54 - 0.46 * cos(2*pi*(0:N-1)'/(N-1)); Daniel@0: else Daniel@0: warning(['WARNING in MIRAUTOCOR: Unknown windowing function ',option.win,' (maybe Signal Processing Toolbox is not installed).']); Daniel@0: disp('No windowing performed.') Daniel@0: w = ones(size(sl,1),1); Daniel@0: end Daniel@0: end Daniel@0: kw = repmat(w,[1,size(sl,2),size(sl,3)]); Daniel@0: sl = sl.* kw; Daniel@0: end Daniel@0: Daniel@0: if strcmpi(option.scaleopt,'coeff') Daniel@0: scaleopt = 'none'; Daniel@0: else Daniel@0: scaleopt = option.scaleopt; Daniel@0: end Daniel@0: c = zeros(masp,size(sl,2),size(sl,3)); Daniel@0: for i = 1:size(sl,2) Daniel@0: for j = 1:size(sl,3) Daniel@0: if option.gener == 2 Daniel@0: cc = xcorr(sl(:,i,j),masp-1,scaleopt); Daniel@0: c(:,i,j) = cc(masp:end); Daniel@0: else Daniel@0: ss = abs(fft(sl(:,i,j))); Daniel@0: ss = ss.^option.gener; Daniel@0: cc = ifft(ss); Daniel@0: ll = (0:masp-1); Daniel@0: c(:,i,j) = cc(ll+1); Daniel@0: end Daniel@0: end Daniel@0: if strcmpi(option.scaleopt,'coeff') && option.gener == 2 Daniel@0: % to be adapted to generalized autocor Daniel@0: c(:,i,:) = c(:,i,:)/xcorr(sum(sl(:,i,:),3),0); Daniel@0: % This is a kind of generalization of the 'coeff' Daniel@0: % normalization for multi-channels signals. In the Daniel@0: % original 'coeff' option, the autocorrelation at zero Daniel@0: % lag is identically 1.0. In this multi-channels Daniel@0: % version, the autocorrelation at zero lag is such that Daniel@0: % the sum over channels becomes identically 1.0. Daniel@0: end Daniel@0: end Daniel@0: coeffk{l} = c(misp:end,:,:); Daniel@0: pl = pl(find(pl(:,1,1) >=mi),:,:); Daniel@0: lagsk{l} = pl(1:min(size(coeffk{l},1),size(pl,1)),:,:); Daniel@0: windk{l} = kw; Daniel@0: end Daniel@0: coeff{k} = coeffk; Daniel@0: lags{k} = lagsk; Daniel@0: wind{k} = windk; Daniel@0: end Daniel@0: a = set(a,'Coeff',coeff,'Delay',lags,'Window',wind); Daniel@0: if not(isempty(postoption)) Daniel@0: a = post(a,postoption); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: Daniel@0: function a = post(a,option) Daniel@0: debug = 0; Daniel@0: coeff = get(a,'Coeff'); Daniel@0: lags = get(a,'Delay'); Daniel@0: wind = get(a,'Window'); Daniel@0: freq = option.fr && not(get(a,'FreqDomain')); Daniel@0: if isequal(option.e,1) Daniel@0: option.e = 2:10; Daniel@0: end Daniel@0: if max(option.e) > 1 Daniel@0: pa = mirpeaks(a,'NoBegin','NoEnd','Contrast',.01); Daniel@0: va = mirpeaks(a,'Valleys','Contrast',.01); Daniel@0: pv = get(pa,'PeakVal'); Daniel@0: vv = get(va,'PeakVal'); Daniel@0: end Daniel@0: for k = 1:length(coeff) Daniel@0: for l = 1:length(coeff{k}) Daniel@0: c = coeff{k}{l}; % Coefficients of autocorrelation Daniel@0: t = lags{k}{l}; % Delays of autocorrelation Daniel@0: if not(isempty(c)) Daniel@0: if not(isequal(option.nw,0) || strcmpi(option.nw,'No') || ... Daniel@0: strcmpi(option.nw,'Off') || a.normalwindow) % 'NormalWindow' option Daniel@0: xw = zeros(size(c)); Daniel@0: lc = size(c,1); Daniel@0: for j = 1:size(c,3) Daniel@0: for i = 1:size(c,2) Daniel@0: xwij = xcorr(wind{k}{l}(:,i,j),lc,'coeff'); Daniel@0: xw(:,i,j) = xwij(lc+2:end); Daniel@0: end Daniel@0: end Daniel@0: c = c./ xw; Daniel@0: a.normalwindow = 1; Daniel@0: end Daniel@0: if ischar(option.reso) && ... Daniel@0: (strcmpi(option.reso,'ToiviainenSnyder') || ... Daniel@0: strcmpi(option.reso,'Toiviainen') || ... Daniel@0: strcmpi(option.reso,'vanNoorden')) Daniel@0: if isa(a,'mirautocor') && get(a,'FreqDomain') Daniel@0: ll = 1./t; Daniel@0: else Daniel@0: ll = t; Daniel@0: end Daniel@0: if not(option.resocenter) Daniel@0: option.resocenter = .5; Daniel@0: end Daniel@0: if strcmpi(option.reso,'ToiviainenSnyder') || ... Daniel@0: strcmpi(option.reso,'Toiviainen') Daniel@0: w = max(1 - 0.25*(log2(max(ll,1e-12)/option.resocenter)).^2, 0); Daniel@0: elseif strcmpi(option.reso,'vanNoorden') Daniel@0: f0=2.193; b=option.resocenter; Daniel@0: f=1./ll; a1=(f0*f0-f.*f).^2+b*f.^2; a2=f0^4+f.^4; Daniel@0: w=(1./sqrt(a1))-(1./sqrt(a2)); Daniel@0: end Daniel@0: if max(w) == 0 Daniel@0: warning('The resonance curve, not defined for this range of delays, will not be applied.') Daniel@0: else Daniel@0: w = w/max(w); Daniel@0: c = c.* repmat(w,[1,size(c,2),size(c,3)]); Daniel@0: end Daniel@0: end Daniel@0: if option.h Daniel@0: c = hwr(c); Daniel@0: end Daniel@0: if max(option.e) > 1 Daniel@0: if a.freq Daniel@0: freq = 1; Daniel@0: for i = 1:size(c,3) Daniel@0: c(:,:,i) = flipud(c(:,:,i)); Daniel@0: end Daniel@0: t = flipud(1./t); Daniel@0: end Daniel@0: Daniel@0: for g = 1:size(c,2) Daniel@0: for h = 1:size(c,3) Daniel@0: cgh = c(:,g,h); Daniel@0: if length(cgh)>1 Daniel@0: pvk = pv{k}{l}{1,g,h}; Daniel@0: mv = []; Daniel@0: if not(isempty(pvk)) Daniel@0: mp = min(pv{k}{l}{1,g,h}); %Lowest peak Daniel@0: vvv = vv{k}{l}{1,g,h}; %Valleys Daniel@0: mv = vvv(find(vvv0,1)-1; Daniel@0: % number of removed points Daniel@0: if isempty(deter) Daniel@0: deter = 0; Daniel@0: end Daniel@0: cgh2(1:deter) = []; Daniel@0: tgh2(1:deter) = []; Daniel@0: coef = cgh2(2)-cgh2(1); Daniel@0: end Daniel@0: Daniel@0: if coef > 0 Daniel@0: % initial ascending slope prolonged to the left Daniel@0: % until it reaches the x-axis Daniel@0: while cgh2(1) > 0 Daniel@0: coef = coef*1.1; Daniel@0: % the further to the left, ... Daniel@0: % the more ascending is the slope Daniel@0: % (not sure it always works, though...) Daniel@0: inter = inter+1; Daniel@0: % number of added points Daniel@0: cgh2 = [cgh2(1)-coef; cgh2]; Daniel@0: tgh2 = [tgh2(1)-tcoef; tgh2]; Daniel@0: end Daniel@0: cgh2(1) = 0; Daniel@0: end Daniel@0: Daniel@0: for i = option.e % Enhancing procedure Daniel@0: % option.e is the list of scaling factors Daniel@0: % i is the scaling factor Daniel@0: if i Daniel@0: be = find(tgh2 & tgh2/i >= tgh2(1),1); Daniel@0: % starting point of the substraction Daniel@0: % on the X-axis Daniel@0: Daniel@0: if not(isempty(be)) Daniel@0: ic = interp1(tgh2,cgh2,tgh2/i); Daniel@0: % The scaled autocorrelation Daniel@0: ic(1:be-1) = 0; Daniel@0: ic(find(isnan(ic))) = Inf; Daniel@0: % All the NaN values are changed Daniel@0: % into 0 in the resulting curve Daniel@0: ic = max(ic,0); Daniel@0: Daniel@0: if debug Daniel@0: hold off,plot(tgh2,cgh2) Daniel@0: end Daniel@0: Daniel@0: cgh2 = cgh2 - ic; Daniel@0: % The scaled autocorrelation Daniel@0: % is substracted to the initial one Daniel@0: Daniel@0: cgh2 = max(cgh2,0); Daniel@0: % Half-wave rectification Daniel@0: Daniel@0: if debug Daniel@0: hold on,plot(tgh2,ic,'r') Daniel@0: hold on,plot(tgh2,cgh2,'g') Daniel@0: drawnow Daniel@0: figure Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: % The temporary modifications are Daniel@0: % removed from the final curve Daniel@0: if inter>=deter Daniel@0: c(:,g,h) = cgh2(inter-deter+1:end); Daniel@0: if not(isempty(mv)) Daniel@0: c(:,g,h) = c(:,g,h) + mv; Daniel@0: end Daniel@0: else Daniel@0: c(:,g,h) = [zeros(deter-inter,1);cgh2]; Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: if freq Daniel@0: if t(1,1) == 0 Daniel@0: c = c(2:end,:,:); Daniel@0: t = t(2:end,:,:); Daniel@0: end Daniel@0: for i = 1:size(c,3) Daniel@0: c(:,:,i) = flipud(c(:,:,i)); Daniel@0: end Daniel@0: t = flipud(1./t); Daniel@0: end Daniel@0: coeff{k}{l} = c; Daniel@0: lags{k}{l} = t; Daniel@0: end Daniel@0: end Daniel@0: end Daniel@0: a = set(a,'Coeff',coeff,'Delay',lags,'Freq'); Daniel@0: if freq Daniel@0: a = set(a,'FreqDomain',1,'Abs','frequency (Hz)'); Daniel@0: end Daniel@0: Daniel@0: Daniel@0: function [y orig] = eachchunk(orig,option,missing,postchunk) Daniel@0: option.scaleopt = 'none'; Daniel@0: y = mirautocor(orig,option); Daniel@0: Daniel@0: Daniel@0: function y = combinechunk(old,new) Daniel@0: do = get(old,'Data'); Daniel@0: do = do{1}{1}; Daniel@0: dn = get(new,'Data'); Daniel@0: dn = dn{1}{1}; Daniel@0: if abs(size(dn,1)-size(do,1)) <= 2 % Probleme of border fluctuation Daniel@0: mi = min(size(dn,1),size(do,1)); Daniel@0: dn = dn(1:mi,:,:); Daniel@0: do = do(1:mi,:,:); Daniel@0: elseif length(dn) < length(do) Daniel@0: dn(length(do),:,:) = 0; % Zero-padding Daniel@0: end Daniel@0: y = set(old,'ChunkData',do+dn);