0001 function [topcs,pwr,y]=nt_pca0(x,shifts,nkeep,threshold,w)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 if nargin<1; error('!'); end
0018 if nargin<2||isempty(shifts); shifts=[0]; end
0019 if nargin<3; nkeep=[]; end
0020 if nargin<4||isempty(threshold); threshold=0; end
0021 if nargin<5; w=[]; end
0022
0023 [m,n,o]=size(x);
0024
0025
0026
0027
0028
0029 if isempty(w);
0030 c=nt_cov(x,shifts);
0031 else
0032 c=nt_cov(x,shifts,w);
0033 end
0034
0035
0036 if ~isempty(nkeep)
0037 [topcs,ev]=nt_pcarot(c,nkeep);
0038 else
0039 [topcs,ev]=nt_pcarot(c);
0040 end
0041
0042
0043
0044
0045 pwr=diag(topcs'*c*topcs)/(m*o);
0046 idx=find(pwr>=threshold*max(pwr));
0047 pwr=pwr(idx)';
0048 topcs=topcs(:,idx);
0049
0050
0051 if nargout>2
0052 y=nt_mmat(x,topcs);
0053 end
0054
0055
0056 if 0
0057 x=randn(1000,10);
0058 [topcs,pwr,y]=nt_pca0(x);
0059 figure(1); plot(pwr);
0060 figure(2); subplot 121; plot(y); subplot 122; plot(x*topcs);
0061 end
0062 if 0
0063 x=zeros(1000,10);
0064 [topcs,pwr,y]=nt_pca0(x);
0065 figure(1); plot(pwr);
0066 figure(2); subplot 121; plot(y); subplot 122; plot(x*topcs);
0067 end
0068 if 0
0069 x=sin(2*pi*3*(1:1000)'/1000)*randn(1,10);
0070 x=2*x + randn(size(x));
0071 [topcs,pwr,y]=nt_pca0(x);
0072 figure(1); plot(pwr);
0073 figure(2); subplot 121; plot(x); subplot 122; plot(x*topcs);
0074 end
0075
0076
0077