[ses_mask, bad_chans, bad_trials] = bad_from_mask(ses_mask, badspecs) Returns bad channels and modifies ses_mask based on current ses_mask and specs in badspecs .prop_bad_chan -- proportion of bad channels for trial to be declared bad .prop_bad_trials -- proportion of bad trials for channel to be declared bad ses_mask is a binary mask. Ones indicate a good trial/channel. Zero is bad. ses_mask is an M X N matrix in which the M rows represent trials and N columns represent channels.
0001 function [ses_mask, bad_chans, bad_trials] = bad_from_mask(ses_mask, bs) 0002 % 0003 % [ses_mask, bad_chans, bad_trials] = bad_from_mask(ses_mask, badspecs) 0004 % 0005 % Returns bad channels and modifies ses_mask based on current ses_mask and 0006 % specs in badspecs 0007 % .prop_bad_chan -- proportion of bad channels for trial to be declared bad 0008 % .prop_bad_trials -- proportion of bad trials for channel to be declared bad 0009 % 0010 % ses_mask is a binary mask. Ones indicate a good trial/channel. Zero is 0011 % bad. ses_mask is an M X N matrix in which the M rows represent trials and N 0012 % columns represent channels. 0013 0014 % Modification history: 0015 % 0016 % 01/24/00 PJ 0017 % 07/15/01 PJ Added refchan handling 0018 0019 if bs.add_refchan2mask 0020 ses_mask(:,end+1) = 1; 0021 end 0022 0023 ses_mask = ~ses_mask; 0024 0025 bad_chans = find(sum(ses_mask) >= bs.prop_bad_trials*size(ses_mask,1)); 0026 bad_trials = find(sum(ses_mask,2) >= bs.prop_bad_chan*size(ses_mask,2)); 0027 0028 ses_mask(bad_trials,:) = 1; 0029 ses_mask(:,bad_chans) = 1; 0030 0031 ses_mask = ~ses_mask; 0032 0033 return 0034