1
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
2
<!DOCTYPE MAN SYSTEM "../../manrev.dtd">
4
<LANGUAGE>eng</LANGUAGE>
6
<TYPE>Scilab Function</TYPE>
7
<DATE>April 1993</DATE>
8
<SHORT_DESCRIPTION name="corr"> correlation, covariance</SHORT_DESCRIPTION>
10
<CALLING_SEQUENCE_ITEM>[cov,Mean]=corr(x,[y],nlags) </CALLING_SEQUENCE_ITEM>
11
<CALLING_SEQUENCE_ITEM>[cov,Mean]=corr('fft',xmacro,[ymacro],n,sect) </CALLING_SEQUENCE_ITEM>
12
<CALLING_SEQUENCE_ITEM> </CALLING_SEQUENCE_ITEM>
13
<CALLING_SEQUENCE_ITEM>[w,xu]=corr('updt',x1,[y1],w0) </CALLING_SEQUENCE_ITEM>
14
<CALLING_SEQUENCE_ITEM>[w,xu]=corr('updt',x2,[y2],w,xu) </CALLING_SEQUENCE_ITEM>
15
<CALLING_SEQUENCE_ITEM> ... </CALLING_SEQUENCE_ITEM>
16
<CALLING_SEQUENCE_ITEM>[wk]=corr('updt',xk,[yk],w,xu) </CALLING_SEQUENCE_ITEM>
21
<PARAM_NAME>x</PARAM_NAME>
23
<SP>: a real vector</SP>
27
<PARAM_NAME>y</PARAM_NAME>
29
<SP>: a real vector, default value x.</SP>
33
<PARAM_NAME>nlags</PARAM_NAME>
35
<SP>: integer, number of correlation coefficients desired.</SP>
39
<PARAM_NAME>xmacro</PARAM_NAME>
41
<SP>: a scilab external (see below).</SP>
45
<PARAM_NAME>ymacro</PARAM_NAME>
47
<SP>: a scilab external (see below), default value xmacro</SP>
51
<PARAM_NAME>n</PARAM_NAME>
53
<SP>: an integer, total size of the sequence (see below).</SP>
57
<PARAM_NAME>sect</PARAM_NAME>
59
<SP>: size of sections of the sequence (see below).</SP>
63
<PARAM_NAME>xi</PARAM_NAME>
65
<SP>: a real vector</SP>
69
<PARAM_NAME>yi</PARAM_NAME>
71
<SP>: a real vector,default value xi.</SP>
75
<PARAM_NAME>cov</PARAM_NAME>
77
<SP>: real vector, the correlation coefficients</SP>
81
<PARAM_NAME>Mean</PARAM_NAME>
83
<SP>: real number or vector, the mean of x and if given y</SP>
97
cov(m) = > (x(k) - xmean) (y(m+k) - ymean) * ---
104
for m=0,..,<VERB>nlag-1</VERB> and two vectors <VERB>x=[x(1),..,x(n)]</VERB>
105
<VERB>y=[y(1),..,y(n)]</VERB>
108
Note that if x and y sequences are differents corr(x,y,...) is
109
different with corr(y,x,...)
112
<DESCRIPTION_ITEM label="Short sequences">
113
<SP><VERB>[cov,Mean]=corr(x,[y],nlags)</VERB> returns the first nlags
114
correlation coefficients and Mean = <VERB>mean(x)</VERB>
115
(mean of <VERB>[x,y]</VERB> if <VERB>y</VERB> is an argument).
116
The sequence <VERB>x</VERB> (resp. <VERB>y</VERB>) is assumed real, and <VERB>x</VERB>
117
and <VERB>y</VERB> are of same dimension n.</SP>
119
<DESCRIPTION_ITEM label="Long sequences">
120
<SP><VERB>[cov,Mean]=corr('fft',xmacro,[ymacro],n,sect)</VERB> Here <VERB>xmacro</VERB> is either</SP>
124
a function of type <VERB>[xx]=xmacro(sect,istart)</VERB> which
125
returns a vector <VERB>xx</VERB> of dimension
126
<VERB>nsect</VERB> containing the part of the sequence with
127
indices from <VERB>istart</VERB> to
128
<VERB>istart+sect-1</VERB>.</P>
132
a fortran subroutine or C procedure which performs the same
133
calculation. (See the source code of <VERB>dgetx</VERB> for an
134
example). <VERB>n</VERB> = total size of the
135
sequence. <VERB>sect</VERB> = size of sections of the
136
sequence. <VERB>sect</VERB> must be a power of
137
2. <VERB>cov</VERB> has dimension
138
<VERB>sect</VERB>. Calculation is performed by FFT.</P>
140
</DESCRIPTION_INDENT>
142
<DESCRIPTION_ITEM label="Updating method">
145
[w,xu]=corr('updt',x1,[y1],w0)
146
[w,xu]=corr('updt',x2,[y2],w,xu)
148
wk=corr('updt',xk,[yk],w,xu)
152
With this calling sequence the calculation is updated at each
153
call to <VERB>corr</VERB>.</P>
156
w0 = 0*ones(1,2*nlags);
160
<P><VERB>x1,x2,...</VERB> are parts of <VERB>x</VERB> such that
161
<VERB>x=[x1,x2,...]</VERB> and sizes of <VERB>xi</VERB> a power of
162
2. To get <VERB>nlags</VERB> coefficients a final fft must be
163
performed <VERB>c=fft(w,1)/n</VERB>; <VERB>cov=c(1nlags)</VERB>
164
(<VERB>n</VERB> is the size of <VERB>x (y)</VERB>). Caution: this
165
calling sequence assumes that <VERB>xmean = ymean = 0</VERB>.</P>
167
</DESCRIPTION_INDENT>
171
x=%pi/10:%pi/10:102.4*%pi;
172
rand('seed');rand('normal');
173
y=[.8*sin(x)+.8*sin(2*x)+rand(x);.8*sin(x)+.8*sin(1.99*x)+rand(x)];
175
for j=1:2,for k=1:2,c=[c;corr(y(k,:),y(j,:),64)];end;end;
176
c=matrix(c,2,128);cov=[];
177
for j=1:64,cov=[cov;c(:,(j-1)*2+1:2*j)];end;
180
rand('normal');x=rand(1,256);y=-x;
181
deff('[z]=xx(inc,is)','z=x(is:is+inc-1)');
182
deff('[z]=yy(inc,is)','z=y(is:is+inc-1)');
183
[c,mxy]=corr(x,y,32);
184
x=x-mxy(1)*ones(x);y=y-mxy(2)*ones(y); //centring
185
c1=corr(x,y,32);c2=corr(x,32);
187
[c3,m3]=corr('fft',xx,yy,256,32);
189
[c4,m4]=corr('fft',xx,256,32);
190
norm(m3,1),norm(m4,1)
191
norm(c3-c1,1),norm(c4-c2,1)
192
x1=x(1:128);x2=x(129:256);
193
y1=y(1:128);y2=y(129:256);
194
w0=0*ones(1:64); //32 coeffs
195
[w1,xu]=corr('u',x1,y1,w0);w2=corr('u',x2,y2,w1,xu);
196
zz=real(fft(w2,1))/256;c5=zz(1:32);
198
[w1,xu]=corr('u',x1,w0);w2=corr('u',x2,w1,xu);
199
zz=real(fft(w2,1))/256;c6=zz(1:32);
202
// test for Fortran or C external
204
deff('[y]=xmacro(sec,ist)','y=sin(ist:(ist+sec-1))');
206
[cc1,mm1]=corr(x,2^3);
207
[cc,mm]=corr('fft',xmacro,100,2^3);
208
[cc2,mm2]=corr('fft','corexx',100,2^3);
209
[maxi(abs(cc-cc1)),maxi(abs(mm-mm1)),maxi(abs(cc-cc2)),maxi(abs(mm-mm2))]
211
deff('[y]=ymacro(sec,ist)','y=cos(ist:(ist+sec-1))');
213
[cc1,mm1]=corr(x,y,2^3);
214
[cc,mm]=corr('fft',xmacro,ymacro,100,2^3);
215
[cc2,mm2]=corr('fft','corexx','corexy',100,2^3);
216
[maxi(abs(cc-cc1)),maxi(abs(mm-mm1)),maxi(abs(cc-cc2)),maxi(abs(mm-mm2))]