tomwalters@0: % method of class @signal tomwalters@0: % function sig=crosscorrelate(sig1,sig2,[delay_start],[delay_stop],[normalization_mode]) tomwalters@0: % tomwalters@0: % calculates the cross corrlelation between the signals sig1 and sig2. The tomwalters@0: % return value is a signal that covers the correlation between the two tomwalters@0: % signals between delay_start and delay_stop. tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % sig1: original @signal tomwalters@0: % sig2: @signal to correlate with tomwalters@0: % delay_start: start of the correlation : default -length(sig) tomwalters@0: % delay_stop: longest delay of the correlation : default length(sig) tomwalters@0: % normalization_mode: normalizateion: default: 'biased' (see help 'xcorr') tomwalters@0: % tomwalters@0: % RETURN VALUE: tomwalters@0: % @sig: the correlation values at each delay tomwalters@0: % bleeck@3: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: tomwalters@0: tomwalters@0: function sig=crosscorrelate(sig1,sig2,delay_start,delay_stop,normalization_mode) tomwalters@0: tomwalters@0: if nargin < 5 tomwalters@0: normalization_mode='biased'; tomwalters@0: end tomwalters@0: if nargin < 4 tomwalters@0: l1=getlength(sig1); tomwalters@0: l2=getlength(sig2); tomwalters@0: delay_stop=min(l1,l2); % the smaller of both length tomwalters@0: end tomwalters@0: if nargin < 3 tomwalters@0: delay_start=-delay_stop; % the tomwalters@0: end tomwalters@0: tomwalters@0: % by this time the signal is shifted tomwalters@0: deltatime=delay_stop+delay_start; tomwalters@0: tomwalters@0: values1=getvalues(sig1); tomwalters@0: values2=getvalues(sig2); tomwalters@0: tomwalters@0: sr=getsr(sig1); tomwalters@0: maxlags1=delay_stop*sr; tomwalters@0: maxlags2=-delay_start*sr; tomwalters@0: tomwalters@0: maxlags=floor(max(maxlags1,maxlags2)); tomwalters@0: tomwalters@0: % do the crosscorrelation: tomwalters@0: corrcovs=xcorr(values1,values2,maxlags,normalization_mode); tomwalters@0: tomwalters@0: % return a signal: tomwalters@0: sig=signal(corrcovs,sr); tomwalters@0: if deltatime > 0 tomwalters@0: sig=getpart(sig,deltatime); % compensate for a possible asymmetric shift tomwalters@0: else tomwalters@0: sig=getpart(sig,0,delay_stop-delay_start); % compensate for a possible asymmetric shift tomwalters@0: end tomwalters@0: sig=setstarttime(sig,delay_start); tomwalters@0: sig=setname(sig,'CrossCorrelation'); tomwalters@0: sig=setunit_x(sig,'delay (ms)'); tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: