Skip to content

Commit

Permalink
proc_interp() updated with optional type=='channel', and to interacti…
Browse files Browse the repository at this point in the history
…vely allow inputs for bad channel percent artifact
  • Loading branch information
sjburwell committed Dec 27, 2018
1 parent 6ca8700 commit f15ddbb
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions functions/procfunc/proc_interp.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
% 'montage' - file containing channel labels/locations.
% If 'type'=='full', required as input.
% options: >> help readlocs()
% 'interpmaj' - if a channel is marked as artifact for majority of dataset,
% interpolate totally.
% 'interpmaj' - if a channel is marked as artifact for >P% of time,
% interpolate totally. P defined in "rejpctbad" below (default: 50%)
% options: yes = 1 (default);
% no = 0;
% 'rejpctbad' - maximum percent of time (epochs) for a given channel marked as artifact
% allowed before interpolating the whole thing
% options: integer value between 0 and 100,
% default = 50;
% 'rejthresh' - maximum percent of channels within an epoch before skipping
% and tagging epoch as artifact
% options: integer value between 0 and 100,
Expand Down Expand Up @@ -70,6 +74,20 @@
disp(['Cannot find file: ' args.montage]);
return
end
elseif ~isempty(strmatch('channel',args.type)),
intfull = 0;
if exist(args.montage,'file'),
chanlocs = readlocs(args.montage); if isempty(chanlocs), disp(' chanlocs invalid!'); end
fldiff = setdiff(fieldnames(chanlocs), fieldnames(EEG.chanlocs));
if ~isempty(fldiff),
for ff = 1:length(fldiff),
chanlocs = rmfield(chanlocs, fldiff{ff});
end
end
else
disp(['Cannot find file: ' args.montage]);
return
end
elseif ~isempty(strmatch('artifact',args.type)),
intfull = 0;
chanlocs = EEG.chanlocs;
Expand All @@ -82,25 +100,31 @@
if ~isfield(args,'rejthresh')||isempty(args.rejthresh),
args.rejthresh = 25;
end
if ~isfield(args,'rejpctbad')||isempty(args.rejpctbad),
args.rejpctbad = 50;
end
if ~isfield(args,'rejreject')||isempty(args.rejreject),
args.rejreject = 0;
end

% initiate interpE
EEG = eeg_rejsuperpose(EEG,1,1,1,1,1,1,1,1);
%EEG = eeg_hist(EEG, 'EEG = eeg_rejsuperpose(EEG,1,1,1,1,1,1,1,1);');
if isempty(find(EEG.reject.rejglobalE))&&intfull==0,
disp('Rejected channels empty, abort operation');
return
%if isempty(find(EEG.reject.rejglobalE))&&intfull==0, %does this case even make sense???
% disp('Rejected channels empty, abort operation');
% return
if intfull==0,
interpE = zeros([EEG.nbchan EEG.trials]);
elseif isempty(find(EEG.reject.rejglobalE))&&intfull==1,
interpE = zeros([EEG.nbchan EEG.trials]);
else,
interpE = EEG.reject.rejglobalE;
end

% whole-channel; total recode if >50% artifact
% whole-channel; total recode if >% artifact
if args.interpmaj>0,
recode1 = find(sum(interpE')>(.5*EEG.trials));
%recode1 = find(sum(interpE')>((args.rejpctbad/100)*EEG.trials));
recode1 = find(sum(EEG.reject.rejglobalE')>((args.rejpctbad/100)*EEG.trials)); %changed 12-27-18 to accommodate the 'type'=='channel' option
if ~isempty(recode1),
interpE(recode1,:) = 1;
end
Expand Down Expand Up @@ -134,7 +158,7 @@

% reject/interp accounting
if ~isempty(find(rejT))&&args.rejreject==1,
EEG = pop_select(EEG, 'notrial', find(rejT));
EEG = proc_select(EEG, 'notrial', find(rejT));
EEG.reject.rejmanualE = interpE(:,find(rejT==0));
EEG.reject.rejmanual = find(sum(EEG.reject.rejmanualE));
EEG.reject.rejmanualcol = [0.5 0.5 0.5];
Expand Down

0 comments on commit f15ddbb

Please sign in to comment.