surrogate.m

来自「替代数据生成算法。包括常用的随机相位法(shuffle.m and surrog」· M 代码 · 共 117 行

M
117
字号
function xp = surrogate(x,alg,rot)% xp = surrogate(x,alg,rot)% Surrogate data generator% handles multichannel data (channels are columns)% alg = algorithm 1 or 2 (default alg=1)% rot = method of randomizing phases (default rot=1)%     +ve = preserve correlation of channels %     -ve = destroy correlation of channels %       1 = add random phase%       2 = replace phase% if alg = -1 or -2, then apply enpoint correction%%% NB: if using one channel then input vector MUST BE a column vector. MAS.%%Michael Small%3/3/2005%ensmall@polyu.edu.hk% History% Surrogate algorithm 2 ala James Theiler% Written by Tanya Schmah% Modified by Alistair Mees for Matlab 4% Modified by Kevin Judd into a function% Rewritten by Kevin Judd Aug95% Modified by Michael Smallif nargin<3  rot= 1;endif nargin<2  alg= 1;endfatal(~any(abs(alg)==[1 2]),'Only know algorithms 1 and 2');%figure%subplot(211)%plot(x)%drawnow[n,d] = size(x);y= zeros(n,d);if abs(alg)==2  % normal rank  j= (1:n)';  r= randn(size(x));  [sr,ri]= sort(r);  [sx,xi]= sort(x);  [sxi,xii]= sort(xi);  for k=1:d    y(:,k)= sr(xii(:,k));  endelse  y= x;endm= mean(y);y= y-m(ones(n,1),:);% endpoint correctionif alg<0  y0= y(1,:);  y1= y(n,:);  u= (0:n-1)'/(n-1);  c= u*y1 + (1-u)*y0;else  c= 0;end;% fftfy = fft(y-c);% randomize phases (Must be same change each channel)if rot>0  phz= rand(n,1);  phz= phz(:,ones(1,d));else  phz= rand(n,d);endif abs(rot)==1  rot= exp(1) .^ (2*pi*sqrt(-1)*phz);  fyp= fy .* rot;else  rot= exp(1) .^ (2*pi*sqrt(-1)*phz);  fyp= abs(fy) .* rot;end%keyboard% ifftyp= real(ifft(fyp)) + c + m(ones(n,1),:);if abs(alg)==2  [syp,ypi] = sort(yp);  [sypi,ypii] = sort(ypi);  for k=1:d    xp(:,k) = sx(ypii(:,k));  end;else  xp= yp;end;%subplot(212)%plot(xp)return%pause%subplot(211)%xf=filtfilt(ones(1,10)/10,1,x);  plot(xf);%subplot(212)%xpf=filtfilt(ones(1,10)/10,1,xp);plot(xpf);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?