Home > NoiseTools > nt_pca0.m

nt_pca0

PURPOSE ^

[topcs,pwr]=nt_pca0(x,shifts,nkeep,threshold,w) - time-shift pca

SYNOPSIS ^

function [topcs,pwr]=nt_pca0(x,shifts,nkeep,threshold,w)

DESCRIPTION ^

[topcs,pwr]=nt_pca0(x,shifts,nkeep,threshold,w) - time-shift pca

  topcs: matrix to convert data to PCs
  pwr: power per PC

  x: data matrix
  shifts: array of shifts to apply
  nkeep: number of PCs to keep
  w: weight (see nt_cov)
  threshold: remove components with normalized eigenvalues smaller than threshold (default: 0)

 mean is NOT removed prior to processing

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [topcs,pwr]=nt_pca0(x,shifts,nkeep,threshold,w)
0002 %[topcs,pwr]=nt_pca0(x,shifts,nkeep,threshold,w) - time-shift pca
0003 %
0004 %  topcs: matrix to convert data to PCs
0005 %  pwr: power per PC
0006 %
0007 %  x: data matrix
0008 %  shifts: array of shifts to apply
0009 %  nkeep: number of PCs to keep
0010 %  w: weight (see nt_cov)
0011 %  threshold: remove components with normalized eigenvalues smaller than threshold (default: 0)
0012 %
0013 % mean is NOT removed prior to processing
0014 
0015 
0016 if nargin<1; error('!'); end
0017 if nargin<2||isempty(shifts); shifts=[0]; end
0018 if nargin<3; nkeep=[]; end
0019 if nargin<4||isempty(threshold); threshold=0; end
0020 if nargin<5; w=[]; end
0021 
0022 [m,n,o]=size(x);
0023 
0024 % remove mean
0025 %x=fold(demean(unfold(x)),size(x,1));
0026 
0027 % covariance
0028 if isempty(w);
0029     c=nt_cov(x,shifts);
0030 else
0031     c=nt_cov(x,shifts,w);
0032 end
0033 
0034 % PCA matrix
0035 if ~isempty(nkeep)
0036     topcs=nt_pcarot(c,nkeep);
0037 else
0038     topcs=nt_pcarot(c);
0039 end
0040 
0041 %if ~isempty(nkeep); topcs=topcs(:,1:nkeep); end
0042 
0043 % power per PC
0044 pwr=diag(topcs'*c*topcs)/(m*o);
0045 idx=find(pwr/max(pwr)>threshold);
0046 pwr=pwr(idx);
0047 topcs=topcs(:,idx);
0048 
0049 % matrix to normalized PCs
0050 %topcs=topcs*diag(1./sqrt(pwr));

Generated on Mon 10-Nov-2014 14:40:42 by m2html © 2005