function [blocking, chan]=mxflat(data,max_vertical,max_length) mxflat returns epochs that appear to contain amplifier blocking Inputs: data: a 3-D array of EEG data (channel,time,epoch) max_vertical: if two consecutive points differ by this value, then they are assumed not to be part of a segment of amplifier blocking. A good value for this is .2 microvolts. max_length: if more than max_length consecutive points do not differ by more than max_verticle from the initial consecutive point, the epoch is assumed to contaminated by blocking. A good value for this is 10 time points. Output: blocked: a 1-D binary array. a 1 in the nth position of the array indicates that the nth epoch contains blocking chan: a 1-D integer array. Lists the channel in which blocking was detected for each epoch specified by "blocked"
0001 function [blocked, chan]=mxflat(data,max_vertical,max_length) 0002 %function [blocking, chan]=mxflat(data,max_vertical,max_length) 0003 % 0004 %mxflat returns epochs that appear to contain amplifier blocking 0005 % 0006 %Inputs: 0007 %data: a 3-D array of EEG data (channel,time,epoch) 0008 % 0009 %max_vertical: if two consecutive points differ by this value, then 0010 %they are assumed not to be part of a segment of amplifier 0011 %blocking. A good value for this is .2 microvolts. 0012 % 0013 %max_length: if more than max_length consecutive points do not 0014 %differ by more than max_verticle from the initial consecutive 0015 %point, the epoch is assumed to contaminated by blocking. A good 0016 %value for this is 10 time points. 0017 % 0018 %Output: 0019 %blocked: a 1-D binary array. a 1 in the nth position of the 0020 %array indicates that the nth epoch contains blocking 0021 % 0022 %chan: a 1-D integer array. Lists the channel in which blocking 0023 %was detected for each epoch specified by "blocked" 0024 % 0025 0026 s=size(data); 0027 if length(s)~=3 0028 disp('Data should be 3 dimensional'); 0029 return 0030 end 0031 0032 nepochs=s(3); 0033 0034 chan=[]; 0035 blocked=[]; 0036 for a=1:s(3) %number of epochs 0037 blocking(a)=0; 0038 for c=1:s(1) %number of channels 0039 mn=data(c,1,a); 0040 len=1; 0041 for b=2:s(2) %number of points/epoch 0042 %fprintf('%d time %d len\n',b,len); 0043 if (abs(data(c,b,a)-mn)>max_vertical) 0044 len=1; 0045 mn=data(c,b,a); 0046 else 0047 len=len+1; 0048 end 0049 0050 if len>max_length 0051 blocking(a)=1; 0052 chan=[chan c]; 0053 blocked=[blocked a]; 0054 break; 0055 end 0056 end 0057 if (blocking(a)) 0058 break; 0059 end 0060 end 0061 end