Home > NoiseTools > nt_regcov.m

# nt_regcov

## PURPOSE

r=nt_regcov(cxy,cyy,keep,threshold) - regression matrix from cross covariance

## SYNOPSIS

function r=nt_regcov(cxy,cyy,keep,threshold)

## DESCRIPTION

    r=nt_regcov(cxy,cyy,keep,threshold) - regression matrix from cross covariance

      r: matrix to apply to regressor to best model data

      cxy: cross-covariance matrix between data and regressor
      cyy: covariance matrix of regressor
      keep: number of regressor PCs to keep (default: all)
      threshold: eigenvalue threshold for discarding regressor PCs (default: 0)

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_pcarot [topcs,eigenvalues]=pcarot(cov,nkeep,threshold,N) - PCA matrix from covariance
- nt_vecmult y=nt_vecmult(x,v) - multiply all rows or columns of matrix by vector

This function is called by:

- nt_tsr [y,idx,w]=nt_tsr(x,ref,shifts,wx,wref,keep,thresh) - time-shift regression (TSPCA)
- nt_tsr_nodemean [y,idx,w]=nt_tsr_nodemean(x,ref,shifts,wx,wref,keep,thresh) - time-shift regression (TSPCA)
- nt_tsregress [z,idx]=nt_tsregress(x,y,shifts,xw,yw,keep,threshold) - time-shift regression

## SOURCE CODE

    0001 function r=nt_regcov(cxy,cyy,keep,threshold)
    0002 %r=nt_regcov(cxy,cyy,keep,threshold) - regression matrix from cross covariance
    0003 %
    0004 %  r: matrix to apply to regressor to best model data
    0005 %
    0006 %  cxy: cross-covariance matrix between data and regressor
    0007 %  cyy: covariance matrix of regressor
    0008 %  keep: number of regressor PCs to keep (default: all)
    0009 %  threshold: eigenvalue threshold for discarding regressor PCs (default: 0)
    0010
    0011 if nargin<4; threshold=[]; end
    0012 if nargin<3; keep=[]; end
    0013 if nargin<2; error('!'); end
    0014
    0015 % PCA of regressor
    0016 [topcs,eigenvalues]=nt_pcarot(cyy);
    0017
    0018 % discard negligible regressor PCs
    0019 if ~isempty(keep)
    0020     keep=max(keep,size(topcs,2));
    0021     topcs=topcs(:,1:keep);
    0022     eigenvalues=eigenvalues(1:keep);
    0023 end
    0024 if ~isempty(threshold)
    0025     idx=find(eigenvalues/max(eigenvalues)>threshold);
    0026     topcs=topcs(:,idx);
    0027     eigenvalues=eigenvalues(idx);
    0028 end
    0029
    0030 % cross-covariance between data and regressor PCs
    0031 cxy=cxy';
    0032 r=topcs'*cxy;
    0033
    0034 % projection matrix from regressor PCs
    0035 r=nt_vecmult(r,1./eigenvalues');
    0036
    0037 % projection matrix from regressors
    0038 r=topcs*r;
    0039
    0040 return
    0041
    0042
    0043
    0044