Home > NoiseTools > nt_phase_scramble.m

nt_phase_scramble

PURPOSE ^

y=nt_phase_scramble(x) - scramble time but preserve autocorrelation

SYNOPSIS ^

function y=nt_phase_scramble(x)

DESCRIPTION ^

y=nt_phase_scramble(x) - scramble time but preserve autocorrelation

  y: scrambled data

  x: data to scramble (time X channels, or time X channels X trials

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function y=nt_phase_scramble(x)
0002 %y=nt_phase_scramble(x) - scramble time but preserve autocorrelation
0003 %
0004 %  y: scrambled data
0005 %
0006 %  x: data to scramble (time X channels, or time X channels X trials
0007 %
0008 
0009 
0010 if nargin<1; error('!'); end
0011 [nsample,nchan,ntrial]=size(x);
0012 if rem(nsample,2)~=0;
0013     x=x(1:nsample-1,:,:); nsample=nsample-1;
0014 end
0015 
0016 topcs=nt_pca0(x);
0017 x=nt_mmat(x,topcs);
0018 nchan=size(x,2);
0019 
0020 for iTrial=1:ntrial
0021     xx=x(:,:,iTrial);
0022     yy=fft(xx);
0023 %     phasor=exp(-2*pi*j*rand(nsample/2-1,1)); % same for all channels
0024 %     yy=yy.*repmat([1;phasor; 1; conj(flipud(phasor))],1,nchan);
0025     phasor=exp(-2*pi*j*rand(nsample/2-1,nchan)); % channel-specific
0026     yy=yy.*[ones(1,nchan);phasor; ones(1,nchan); conj(flipud(phasor))];
0027     yy=real(ifft(yy));
0028     y(:,:,iTrial)=yy;
0029 end
0030 
0031 y=nt_mmat(y,pinv(topcs));

Generated on Mon 01-Oct-2018 16:21:39 by m2html © 2005