Home > NoiseTools > nt_pcarot.m

# nt_pcarot

## PURPOSE

[topcs,eigenvalues]=pcarot(cov,nkeep,threshold,N) - PCA matrix from covariance

## SYNOPSIS

function [topcs,eigenvalues]=nt_pcarot(cov,nkeep,threshold,N)

## DESCRIPTION

     [topcs,eigenvalues]=pcarot(cov,nkeep,threshold,N) - PCA matrix from covariance

      topcs: PCA rotation matrix
      eigenvalues: PCA eigenvalues

      cov: covariance matrix
      nkeep: number of component to keep
      thresholds: discard components below this threshold
      N: eigs' K parameter (if absent: use eig)

     NoiseTools

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- nt_dss0 [todss,pwr1,pwr2]=nt_dss0(c0,c1,keep1,keep2) - dss from covariance
- nt_inpaint function y=nt_inpaint(x,w) - weighted interpolation based on correlation structure
- nt_outliers [w,y]=nt_outliers(x,w,thresh,niter) - detect outliers based on weighted correlation structure
- nt_pca [z,idx]=nt_pca(x,shifts,nkeep,threshold,w) - time-shift pca
- nt_pca0 [topcs,pwr,y]=nt_pca0(x,shifts,nkeep,threshold,w) - time-shift pca
- nt_qpca0 [tosquares,quads,D]=nt_qpca0(x,npcs,nsmooth,nquads) - quadratic PCA
- nt_regcov r=nt_regcov(cxy,cyy,keep,threshold) - regression matrix from cross covariance
- nt_sns0 r=nt_sns0(c,nneigbors,skip,wc) - sensor noise suppression
- nt_star [y,w,ww]=nt_star(x,thresh,closest,depth) - sensor noise suppression
- nt_star2 [y,w,ww]=nt_star2(x,thresh,closest,w) - sensor noise suppression
- nt_whiten [A,y]=nt_whiten(x,N) - whiten spectrally using pca

## SOURCE CODE

    0001 function [topcs,eigenvalues]=nt_pcarot(cov,nkeep,threshold,N)
    0002 % [topcs,eigenvalues]=pcarot(cov,nkeep,threshold,N) - PCA matrix from covariance
    0003 %
    0004 %  topcs: PCA rotation matrix
    0005 %  eigenvalues: PCA eigenvalues
    0006 %
    0007 %  cov: covariance matrix
    0008 %  nkeep: number of component to keep
    0009 %  thresholds: discard components below this threshold
    0010 %  N: eigs' K parameter (if absent: use eig)
    0011 %
    0012 % NoiseTools
    0013
    0014 if nargin<4; N=[]; end
    0015 if nargin<3; threshold=[]; end
    0016 if nargin<2; nkeep=[]; end
    0017
    0018 if ~isempty(N);
    0019     [V, S] = eigs(cov,N) ;
    0020 else
    0021     [V, S] = eig(cov) ;
    0022 end
    0023
    0024 V=real(V);
    0025 S=real(S);
    0026 [eigenvalues, idx] = sort(diag(S)', 'descend') ;
    0027 topcs = V(:,idx);
    0028
    0029 % truncate
    0030 if ~isempty (threshold)
    0031     ii=find(eigenvalues/eigenvalues(1)>threshold);
    0032     topcs=topcs(:,ii);
    0033     eigenvalues=eigenvalues(ii);
    0034 end
    0035
    0036 if ~isempty(nkeep)
    0037     nkeep=min(nkeep,size(topcs,2));
    0038     topcs=topcs(:,1:nkeep);
    0039     eigenvalues=eigenvalues(1:nkeep);
    0040 end