Newer
Older
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
function [c_out,s_out]=xcf(x,y,t,flag)
%XCF Computes and plots crosscorrelation.
% [C,S]=XCF(X,Y [,T,FLAG]) computes crosscorrelation C
% between the data in the vectors X and Y with the maximal
% lag T (optional). If FLAG is set, the plot is suppressed.
% The optional output S stores the 5% significance level.
%
% See also COR, COV, XCORR, ACF
% Copyright (c) 2001-2002 by AMRON
% Norbert Marwan, Potsdam University, Germany
% http://www.agnld.uni-potsdam.de
%
% $Date$
% $Revision$
%
% $Log$
%
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or any later version.
error(nargchk(1,4,nargin));
% check the input
if nargin<2
y=x;
end
if length(x)~=length(y)
error('The lengths of x and y must match.')
end
if nargin<3
t=[];
end
if nargin<4
flag=0;
end
% check if xcorr exist
if isempty(which('xcorr'))
disp('Sorry, signal processing toolbox needed.')
if nargout==1
c_out(1:t)=NaN;
elseif nargout==2
c_out(1:t)=NaN;
s_out(1:t)=NaN;
end
else
% compute xcf
x=trafo(x);
y=trafo(y);
[c, s]=xcorr(x,y,t,'coeff');
c=flipud(c);
s=s';
L=length(x)-abs(s);
si=2./sqrt(L+2);
% output
if flag==0
bar(s,c,'k')
hold on
plot(s,si,'r-.')
plot(s,-si,'r-.')
line([0 0],[-1 1],'linestyle',':')
ha=axis;
line([ha(1) ha(2)],[0 0],'linestyle',':')
hold off
end
if nargout==1
c_out=c;
elseif nargout==2
c_out=c;
s_out=si;
end
end