Untitled.m
上传用户:nxf103
上传日期:2017-12-04
资源大小:2690k
文件大小:1k
开发平台:

Matlab

  1. load x00;
  2. load t05;
  3. PCA_num=11
  4. %x00=[x00(1,:); x00(80,:);x00(120,:)];
  5. [tr,meanp,stdp] = prestd(x00');
  6. te = trastd(t05',meanp,stdp);
  7. tr=tr';
  8. te=te';
  9. trd=data(tr);
  10. ted=data(te);
  11. %[r,a]=train(kpca,tr);
  12. %%%%% %主元分析%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  13. [pc,score,latent,tsquare]=princomp(trd);
  14.   PCA=pc(:,1:PCA_num);
  15.   score_PCA=score(:,1:PCA_num);
  16.   latent_PCA=diag(latent(1:PCA_num));
  17. %%%%% %新测试数据(故障数据)作主元分析%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  18.  [n1,m1]=size(t15); 
  19. PCA_Test=zeros(n1,PCA_num);
  20.   Fault_guji=zeros(n1,m1);
  21.   TT=zeros(1,n1);
  22. for i=1:n1,
  23.      for j=1:PCA_num,
  24.        PCA_Test(i,j)=ted(i,:)*PCA(:,j); 
  25.        ted_guji(i,:)=ted_guji(i,:)+ted(i,:)*PCA(:,j)*PCA(:,j)';
  26.      end
  27.   %求T2统计
  28.   TT(i)=PCA_Test(i,:)*inv(latent_PCA)*PCA_Test(i,:)';
  29.   %求SPE统计
  30. end 
  31.  ted_ee=ted-ted_guji;
  32.   for i=1:n1,
  33.   ted_SPE(i)=ted_ee(i,:)*ted_ee(i,:)';
  34.   end
  35.   figure(1);  
  36.    subplot(2,1,1);
  37.    plot(TT);
  38.    subplot(2,1,2);
  39.    plot(ted_SPE);
  40.    title('fault SPE');