Global Index (all files) (short | long) | Local Index (files in subdir) (short | long)
a = cross_corr(x1, x2, lags);
a = cross_corr(x1, x2, lags); Inputs: x is the input data vector lags is -length(x):length(x), unless otherwise specified Negative lags imply x1 LEADS x2 Outputs: a is the cross-correlation function at lags specified by 'lags'
function a = cross_corr(x1, x2, lags); if ~all([length(size(x1))==2 , ismember(1, size(x1))]); error('x1 must be a vector'); end if ~all([length(size(x2))==2 , ismember(1, size(x2))]); error('x2 must be a vector'); end x1 = x1(:); x2 = x2(:); if length(x1) ~= length(x2); error('x1 and x2 must have equal lengths'); end; ntim = length(x1); if nargin == 1; lags = -(ntim-1):(ntim-1); end; nlag = length(lags); a = repmat(NaN, [nlag 1]); for i = 1:nlag; if lags(i) <= 0; ind1 = 1:(ntim+lags(i)); ind2 = (1-lags(i)):ntim; else ind1 = (1+lags(i)):ntim; ind2 = 1:(ntim-lags(i)); end tem = corrcoef(x1(ind1), x2(ind2)); a(i) = tem(1,2); end