Home > eeg > egis > net_utils > ns_artifact_edit.m

ns_artifact_edit

PURPOSE ^

[Epoch, NEpoch,Max_microv,Min_Chan,NBad_chan,bad_chan,mask] = ns_artifact_edit(fid,

SYNOPSIS ^

function [Epoch, NEpoch,Max_microv,Min_Chan,NBad_chan,bad_chan,mask] = ns_artifact_edit(fid,Samp_Rate,NChan, NSamp, NEvent,scale,Epoch,Max_microv,Min_Chan,Lo_Pass,Hi_Pass);

DESCRIPTION ^

 [Epoch, NEpoch,Max_microv,Min_Chan,NBad_chan,bad_chan,mask] = ns_artifact_edit(fid,
       Samp_Rate,NChan, NSamp, NEvent,scale,Epoch,Max_microv,Min_Chan,Lo_Pass,Hi_Pass);
 
 artifact edits NSFragger file generating mask

 fid = legal fid
 Samp_Rate = sampling rate
 NChan = # of channels
 NEvent = # of event tracks
 scale = scale factor between bins and microvolts
 Epoch = analysis epoch length
 Max_microv = ceiling in microvolts at a single channel
 Min_Chan = minimum number of channels to have a legal trial
 Lo_Pass (optional) = low-pass filter frequency  of trial before atifact editing
 Hi_Pass (optional) = hi-pass filter frequency of trial before artifact editing 

 Version 1.0 2/8/97 R.S.

 Note: The code is provided to you for lab use only
    please do not retransmit without permission

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001  function [Epoch, NEpoch,Max_microv,Min_Chan,NBad_chan,bad_chan,mask] = ns_artifact_edit(fid,Samp_Rate,NChan, NSamp, NEvent,scale,Epoch,Max_microv,Min_Chan,Lo_Pass,Hi_Pass); 
0002 % [Epoch, NEpoch,Max_microv,Min_Chan,NBad_chan,bad_chan,mask] = ns_artifact_edit(fid,
0003 %       Samp_Rate,NChan, NSamp, NEvent,scale,Epoch,Max_microv,Min_Chan,Lo_Pass,Hi_Pass);
0004 %
0005 % artifact edits NSFragger file generating mask
0006 %
0007 % fid = legal fid
0008 % Samp_Rate = sampling rate
0009 % NChan = # of channels
0010 % NEvent = # of event tracks
0011 % scale = scale factor between bins and microvolts
0012 % Epoch = analysis epoch length
0013 % Max_microv = ceiling in microvolts at a single channel
0014 % Min_Chan = minimum number of channels to have a legal trial
0015 % Lo_Pass (optional) = low-pass filter frequency  of trial before atifact editing
0016 % Hi_Pass (optional) = hi-pass filter frequency of trial before artifact editing
0017 %
0018 % Version 1.0 2/8/97 R.S.
0019 %
0020 % Note: The code is provided to you for lab use only
0021 %    please do not retransmit without permission
0022 %
0023 
0024 if nargin < 9
0025     error('not enough parameters')
0026 end;
0027 if fid < 1
0028     error('invalid fid');
0029 end;
0030 Max_Bins = (Max_microv/scale).^2;
0031 
0032 NEpoch = fix(NSamp/(Epoch*Samp_Rate));
0033 
0034 mask = ones(NEpoch, NChan+1);
0035  
0036 if nargin >= 10
0037 
0038 [blow,alow] = butter(20,[Lo_Pass/(Samp_Rate/2)]);
0039 
0040 end;
0041 if nargin == 11
0042 
0043 [bband,aband] = butter(3,[Hi_Pass/(Samp_Rate/2) Lo_Pass/(Samp_Rate/2)]);
0044 
0045 end;
0046 
0047 for i = 1:NEpoch
0048      
0049     trialdata = fread(fid,[NChan+NEvent,Samp_Rate*Epoch],'int16');
0050     trialdata = trialdata'; 
0051     if nargin == 10
0052     
0053         for ch =1:NChan
0054             trialdata(:,ch) = filtfilt(blow,alow,trialdata(:,ch));
0055         end;
0056     end;
0057     if nargin == 11
0058         for ch =1:NChan
0059             trialdata(:,ch) = filtfilt(blow,alow,trialdata(:,ch));
0060             trialdata(:,ch) = filtfilt(bband,aband,trialdata(:,ch));
0061         end;
0062     end
0063     trialdata = trialdata.^2;
0064     max_trial = max(trialdata);
0065     bad_chan = find(max_trial > Max_Bins);
0066     mask(i,bad_chan) = zeros(1,size(bad_chan,2));
0067     if (sum(mask(i,:)) < Min_Chan)
0068         mask(i,:) = zeros(1,NChan+1);
0069     end;
0070 end;
0071 
0072 grand_mask = sum(mask);
0073 max_mask = max(grand_mask);
0074 % bad_channels are those which are not good for 75% of trials
0075 
0076 bad_chan = find(grand_mask < 0.75*max_mask);
0077 if bad_chan == []
0078     NBad_chan = 0;
0079 else
0080     NBad_chan = size(bad_chan,2);
0081 end
0082 
0083 
0084 
0085 
0086 
0087

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003