corr correlation, covariance Syntax [cov,Mean] = corr(x,[y],nlags) [cov,Mean] = corr('fft',xmacro,[ymacro],n,sect) [w,xu] = corr('updt',x1,[y1],w0) [w,xu] = corr('updt',x2,[y2],w,xu) ... wk = corr('updt',xk,[yk],w,xu) Arguments x a real vector y a real vector, default value x. nlags integer, number of correlation coefficients desired. xmacro a scilab external (see below). ymacro a scilab external (see below), default value xmacro n an integer, total size of the sequence (see below). sect size of sections of the sequence (see below). xi a real vector yi a real vector,default value xi. cov real vector, the correlation coefficients Mean real number or vector, the mean of x and if given y Description corr(x,y,…) computes cov(m)=\sum_{k=1}^{n-m} \left(x(k)-mean(x)\right)\left(y(m+k)-mean(y)\right) / n for m = 0, …, nlag-1. Note that if x and y sequences are differents corr(x,y,...) is different with corr(y,x,...) Short sequences [cov,Mean]=corr(x,[y],nlags) returns the first nlags correlation coefficients and Mean = mean(x) (mean of [x,y] if y is an argument). The sequence x (resp. y) is assumed real, and x and y are of same dimension n. Long sequences [cov,Mean]=corr('fft',xmacro,[ymacro],n,sect). Here xmacro is either a function of type [xx]=xmacro(sect,istart) which returns a vector xx of dimension nsect containing the part of the sequence with indices from istart to istart+sect-1. a fortran subroutine or C procedure which performs the same calculation. (See the source code of dgetx for an example). n = total size of the sequence. sect = size of sections of the sequence. sect must be a power of 2. cov has dimension sect. Calculation is performed by FFT. Updating method With this syntax the calculation is updated at each call to corr. x1,x2,... are parts of x such that x=[x1,x2,...] and sizes of xi a power of 2. To get nlags coefficients a final fft must be performed c=fft(w,1)/n; cov=c(1nlags) (n is the size of x (y)). Caution: this syntax assumes that xmean = ymean = 0. Examples See also xcorr xcov correl cov covar