/usr/share/octave/packages/3.2/nan-2.4.4/xcovf.m is in octave-nan 2.4.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | function [C,N,LAGS] = xcovf(X,Y,MAXLAG,SCALEOPT)
% XCOVF generates cross-covariance function.
% XCOVF is the same as XCORR except
% X and Y can contain missing values encoded with NaN.
% NaN's are skipped, NaN do not result in a NaN output.
% The output gives NaN only if there are insufficient input data
%
% [C,N,LAGS] = xcovf(X,MAXLAG,SCALEOPT);
% calculates the (auto-)correlation function of X
% [C,N,LAGS] = xcovf(X,Y,MAXLAG,SCALEOPT);
% calculates the crosscorrelation function between X and Y
%
% see also: COVM, XCORR
% $Id: xcovf.m 8223 2011-04-20 09:16:06Z schloegl $
% Copyright (C) 2005,2010 by Alois Schloegl <alois.schloegl@gmail.com>
% This function is part of the NaN-toolbox
% http://pub.ist.ac.at/~schloegl/matlab/NaN/
% 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 <http://www.gnu.org/licenses/>.
if nargin<2,
Y = [];
MAXLAG = [];
SCALEOPT = 'none';
elseif ischar(Y),
SCALEOPT=Y;
Y=[];
MAXLAG = [];
elseif all(size(Y)==1),
if nargin<3
SCALEOPT = 'none';
else
SCALEOPT = MAXLAG;
end;
MAXLAG = Y;
Y = [];
end;
if 0,
elseif isempty(Y) && isempty(MAXLAG)
NX = isnan(X);
X(NX) = 0;
[C,LAGS] = xcorr(X,'none');
[N,LAGS] = xcorr(1-NX,'none');
elseif ~isempty(Y) && isempty(MAXLAG)
NX = isnan(X);
NY = isnan(Y);
X(NX) = 0;
Y(NY) = 0;
[C,LAGS] = xcorr(X,Y,'none');
[N,LAGS] = xcorr(1-NX,1-NY,'none');
elseif isempty(Y) && ~isempty(MAXLAG)
NX = isnan(X);
X(NX) = 0;
[C,LAGS] = xcorr(X,MAXLAG,'none');
[N,LAGS] = xcorr(1-NX,MAXLAG,'none');
elseif ~isempty(Y) && ~isempty(MAXLAG)
NX = isnan(X);
NY = isnan(Y);
X(NX) = 0;
Y(NY) = 0;
[C,LAGS] = xcorr(X,Y,MAXLAG,'none');
[N,LAGS] = xcorr(1-NX,1-NY,MAXLAG,'none');
end;
if 0,
elseif strcmp(SCALEOPT,'none')
% done
elseif strcmp(SCALEOPT,'coeff')
ix = find(LAGS==0);
if ~any(size(X)==1), %% ~isvector(X)
c = C(ix,1:size(X,2)+1:end); %% diagonal elements
v = c.^-0.5; % sqrt(1./c(:));
v = v'*v;
C = C.*repmat(v(:).',size(C,1),1);
elseif isempty(Y)
C = C/C(ix);
else
C = C/sqrt(sumsq(X)*sumsq(Y));
end;
elseif strcmp(SCALEOPT,'biased')
C = C./repmat(max(N),size(C,1),1);
elseif strcmp(SCALEOPT,'unbiased')
C = C./(repmat(max(N),size(C,1),1)-repmat(LAGS,1,size(C,2)));
else
warning('invalid SCALEOPT - not supported');
end;
|