tomwalters@0
|
1 % method of class @signal
|
tomwalters@0
|
2 % function sig=crosscorrelate(sig1,sig2,[delay_start],[delay_stop],[normalization_mode])
|
tomwalters@0
|
3 %
|
tomwalters@0
|
4 % calculates the cross corrlelation between the signals sig1 and sig2. The
|
tomwalters@0
|
5 % return value is a signal that covers the correlation between the two
|
tomwalters@0
|
6 % signals between delay_start and delay_stop.
|
tomwalters@0
|
7 %
|
tomwalters@0
|
8 % INPUT VALUES:
|
tomwalters@0
|
9 % sig1: original @signal
|
tomwalters@0
|
10 % sig2: @signal to correlate with
|
tomwalters@0
|
11 % delay_start: start of the correlation : default -length(sig)
|
tomwalters@0
|
12 % delay_stop: longest delay of the correlation : default length(sig)
|
tomwalters@0
|
13 % normalization_mode: normalizateion: default: 'biased' (see help 'xcorr')
|
tomwalters@0
|
14 %
|
tomwalters@0
|
15 % RETURN VALUE:
|
tomwalters@0
|
16 % @sig: the correlation values at each delay
|
tomwalters@0
|
17 %
|
bleeck@3
|
18 % This external file is included as part of the 'aim-mat' distribution package
|
bleeck@3
|
19 % (c) 2011, University of Southampton
|
bleeck@3
|
20 % Maintained by Stefan Bleeck (bleeck@gmail.com)
|
bleeck@3
|
21 % download of current version is on the soundsoftware site:
|
bleeck@3
|
22 % http://code.soundsoftware.ac.uk/projects/aimmat
|
bleeck@3
|
23 % documentation and everything is on http://www.acousticscale.org
|
bleeck@3
|
24
|
tomwalters@0
|
25
|
tomwalters@0
|
26 function sig=crosscorrelate(sig1,sig2,delay_start,delay_stop,normalization_mode)
|
tomwalters@0
|
27
|
tomwalters@0
|
28 if nargin < 5
|
tomwalters@0
|
29 normalization_mode='biased';
|
tomwalters@0
|
30 end
|
tomwalters@0
|
31 if nargin < 4
|
tomwalters@0
|
32 l1=getlength(sig1);
|
tomwalters@0
|
33 l2=getlength(sig2);
|
tomwalters@0
|
34 delay_stop=min(l1,l2); % the smaller of both length
|
tomwalters@0
|
35 end
|
tomwalters@0
|
36 if nargin < 3
|
tomwalters@0
|
37 delay_start=-delay_stop; % the
|
tomwalters@0
|
38 end
|
tomwalters@0
|
39
|
tomwalters@0
|
40 % by this time the signal is shifted
|
tomwalters@0
|
41 deltatime=delay_stop+delay_start;
|
tomwalters@0
|
42
|
tomwalters@0
|
43 values1=getvalues(sig1);
|
tomwalters@0
|
44 values2=getvalues(sig2);
|
tomwalters@0
|
45
|
tomwalters@0
|
46 sr=getsr(sig1);
|
tomwalters@0
|
47 maxlags1=delay_stop*sr;
|
tomwalters@0
|
48 maxlags2=-delay_start*sr;
|
tomwalters@0
|
49
|
tomwalters@0
|
50 maxlags=floor(max(maxlags1,maxlags2));
|
tomwalters@0
|
51
|
tomwalters@0
|
52 % do the crosscorrelation:
|
tomwalters@0
|
53 corrcovs=xcorr(values1,values2,maxlags,normalization_mode);
|
tomwalters@0
|
54
|
tomwalters@0
|
55 % return a signal:
|
tomwalters@0
|
56 sig=signal(corrcovs,sr);
|
tomwalters@0
|
57 if deltatime > 0
|
tomwalters@0
|
58 sig=getpart(sig,deltatime); % compensate for a possible asymmetric shift
|
tomwalters@0
|
59 else
|
tomwalters@0
|
60 sig=getpart(sig,0,delay_stop-delay_start); % compensate for a possible asymmetric shift
|
tomwalters@0
|
61 end
|
tomwalters@0
|
62 sig=setstarttime(sig,delay_start);
|
tomwalters@0
|
63 sig=setname(sig,'CrossCorrelation');
|
tomwalters@0
|
64 sig=setunit_x(sig,'delay (ms)');
|
tomwalters@0
|
65
|
tomwalters@0
|
66
|
tomwalters@0
|
67
|
tomwalters@0
|
68
|
tomwalters@0
|
69
|
tomwalters@0
|
70
|