X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fsignal-1.1.3%2Fxcov.m;fp=octave_packages%2Fsignal-1.1.3%2Fxcov.m;h=9b51603fb5aabad58169cee8fba03f6180a3cd3f;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/signal-1.1.3/xcov.m b/octave_packages/signal-1.1.3/xcov.m new file mode 100644 index 0000000..9b51603 --- /dev/null +++ b/octave_packages/signal-1.1.3/xcov.m @@ -0,0 +1,62 @@ +## Copyright (C) 1999, 2001 Paul Kienzle +## +## 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 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see . + +## usage: [c, lag] = xcov (X [, Y] [, maxlag] [, scale]) +## +## Compute covariance at various lags [=correlation(x-mean(x),y-mean(y))]. +## +## X: input vector +## Y: if specified, compute cross-covariance between X and Y, +## otherwise compute autocovariance of X. +## maxlag: is specified, use lag range [-maxlag:maxlag], +## otherwise use range [-n+1:n-1]. +## Scale: +## 'biased' for covariance=raw/N, +## 'unbiased' for covariance=raw/(N-|lag|), +## 'coeff' for covariance=raw/(covariance at lag 0), +## 'none' for covariance=raw +## 'none' is the default. +## +## Returns the covariance for each lag in the range, plus an +## optional vector of lags. + +function [retval, lags] = xcov (X, Y, maxlag, scale) + + if (nargin < 1 || nargin > 4) + print_usage; + endif + + if nargin==1 + Y=[]; maxlag=[]; scale=[]; + elseif nargin==2 + maxlag=[]; scale=[]; + if ischar(Y), scale=Y; Y=[]; + elseif isscalar(Y), maxlag=Y; Y=[]; + endif + elseif nargin==3 + scale=[]; + if ischar(maxlag), scale=maxlag; maxlag=[]; endif + if isscalar(Y), maxlag=Y; Y=[]; endif + endif + + ## XXX FIXME XXX --- should let center(Y) deal with [] + ## [retval, lags] = xcorr(center(X), center(Y), maxlag, scale); + if (!isempty(Y)) + [retval, lags] = xcorr(center(X), center(Y), maxlag, scale); + else + [retval, lags] = xcorr(center(X), maxlag, scale); + endif + +endfunction