0001 function x=nt_enforce_stationarity(x,DSR,thresh);
0002
0003
0004
0005
0006
0007
0008
0009
0010 if nargin<3 || isempty(thresh); thresh=10; end
0011 if nargin<2 || isempty(DSR); error('!'); end
0012
0013 nx=size(x,1);
0014 x=nt_unfold(x);
0015
0016
0017 score=inf;
0018
0019 figure(10); clf
0020 subplot 413; plot(x); title('original')
0021
0022 while 1
0023
0024
0025 [A]=nt_cluster_jd((nt_pca(x)),DSR);
0026 figure(10);
0027 subplot 411; plot(A,'.-'); title('cluster mask'); drawnow
0028
0029
0030 if numel(find(A==1))<numel(find(A==2));
0031 idx=find(A==1);
0032 [todss]=nt_dss0(nt_cov(x),nt_cov(x(find(A==1),:)));
0033 else
0034 idx=find(A==2);
0035
0036 [todss]=nt_dss0(nt_cov(x),nt_cov(x(find(A==2),:)));
0037 end
0038
0039 z=nt_mmat(x,todss);
0040 subplot 412; plot(z(:,1)); title('component to remove');
0041 score=mean(z(idx,1).^2)/mean(z(:,1).^2);
0042 disp(['power ratio score: ', num2str(score)]);
0043
0044 if score<thresh
0045 break
0046 end
0047
0048 x(idx,:)=nt_tsr_nodemean(x(idx,:),z(idx,1));
0049 subplot 414; plot(x);
0050 drawnow
0051
0052 end
0053 x=nt_fold(x,nx);
0054 if nargout==0;
0055 clear x
0056 end
0057
0058
0059