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 if nargin<1; error('!'); end
0010 [nsample,nchan,ntrial]=size(x);
0011 if rem(nsample,2)~=0 % pad to multiple of 2
0012     x(nsample+1,:,:)=x(nsample,:,:); 
0013 end
0014 
0015 for iTrial=1:ntrial
0016     xx=x(:,:,iTrial);
0017     yy=fft(xx);
0018 %     phasor=exp(-2*pi*j*rand(nsample/2-1,1)); % same for all channels
0019 %     yy=yy.*repmat([1;phasor; 1; conj(flipud(phasor))],1,nchan);
0020     phasor=exp(-2*pi*j*rand(size(x,1)/2-1,nchan)); % channel-specific
0021     yy=yy.*[ones(1,nchan);phasor; ones(1,nchan); conj(flipud(phasor))];
0022     yy=real(ifft(yy));
0023     y(:,:,iTrial)=yy;
0024 end
0025 
0026 y=y(1:nsample,:,:); % remove padding if need
0027

Generated on Tue 27-Nov-2018 11:03:00 by m2html © 2005