Home > NoiseTools > nt_cov_lags.m

nt_cov_lags

PURPOSE ^

[C,tw,m]=nt_cov_lags(x,y,shifts) - covariance of [x,y] with lags

SYNOPSIS ^

function [C,tw,m]=nt_cov_lags(x,y,shifts)

DESCRIPTION ^

[C,tw,m]=nt_cov_lags(x,y,shifts) - covariance of [x,y] with lags

  C: covariance matrix (3D if length(lags)>1)
  tw: total weight
  m: number of columns in x
  
  x,y: data matrices
  shifts: positive shift means y is delayed relative to x.

  x and y can be time X channels or time X channels X trials.  They can
  also be cell arrays of time X channels matrices.

 See also nt_relshift.

  NoiseTools

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [C,tw,m]=nt_cov_lags(x,y,shifts)
0002 %[C,tw,m]=nt_cov_lags(x,y,shifts) - covariance of [x,y] with lags
0003 %
0004 %  C: covariance matrix (3D if length(lags)>1)
0005 %  tw: total weight
0006 %  m: number of columns in x
0007 %
0008 %  x,y: data matrices
0009 %  shifts: positive shift means y is delayed relative to x.
0010 %
0011 %  x and y can be time X channels or time X channels X trials.  They can
0012 %  also be cell arrays of time X channels matrices.
0013 %
0014 % See also nt_relshift.
0015 %
0016 %  NoiseTools
0017 
0018 if nargin<2; error('!'); end
0019 if nargin<3 || isempty(shifts); shifts=[0]; end
0020 
0021 if isnumeric(x)
0022     % x and y are matrices
0023     if size(y,1)~=size(x,1); error('!'); end
0024     if size(y,3)~=size(x,3); error('!'); end
0025     n=size(x,2)+size(y,2);
0026     C=zeros(n,n,length(shifts));
0027     for iPage=size(x,3)
0028         for iLag=1:length(shifts)
0029             [xx,yy]=nt_relshift(x,y,shifts(iLag));
0030             C(:,:,iLag)=C(:,:,iLag) +[xx,yy]'*[xx,yy];
0031         end
0032     end    
0033     m=size(x,2);
0034     tw=size(x,1)*size(x,3);
0035 else
0036     % x and y are cell arrays
0037     n=size(x{1},2)+size(y{1},2);
0038     C=zeros(n,n,length(shifts));
0039     tw=0;
0040     for iCell=1:length(x);
0041          %disp(iCell)
0042          C=C+nt_cov_lags(x{iCell},y{iCell},shifts);
0043          tw=tw+size(x{iCell},1);
0044     end
0045     m=size(x{1},2);
0046 end
0047

Generated on Tue 27-Nov-2018 11:03:00 by m2html © 2005