1 ## Copyright (C) 1999, 2001 Paul Kienzle <pkienzle@users.sf.net>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
16 ## usage: [c, lag] = xcov (X [, Y] [, maxlag] [, scale])
18 ## Compute covariance at various lags [=correlation(x-mean(x),y-mean(y))].
21 ## Y: if specified, compute cross-covariance between X and Y,
22 ## otherwise compute autocovariance of X.
23 ## maxlag: is specified, use lag range [-maxlag:maxlag],
24 ## otherwise use range [-n+1:n-1].
26 ## 'biased' for covariance=raw/N,
27 ## 'unbiased' for covariance=raw/(N-|lag|),
28 ## 'coeff' for covariance=raw/(covariance at lag 0),
29 ## 'none' for covariance=raw
30 ## 'none' is the default.
32 ## Returns the covariance for each lag in the range, plus an
33 ## optional vector of lags.
35 function [retval, lags] = xcov (X, Y, maxlag, scale)
37 if (nargin < 1 || nargin > 4)
42 Y=[]; maxlag=[]; scale=[];
45 if ischar(Y), scale=Y; Y=[];
46 elseif isscalar(Y), maxlag=Y; Y=[];
50 if ischar(maxlag), scale=maxlag; maxlag=[]; endif
51 if isscalar(Y), maxlag=Y; Y=[]; endif
54 ## XXX FIXME XXX --- should let center(Y) deal with []
55 ## [retval, lags] = xcorr(center(X), center(Y), maxlag, scale);
57 [retval, lags] = xcorr(center(X), center(Y), maxlag, scale);
59 [retval, lags] = xcorr(center(X), maxlag, scale);