Skip to content

Commit

Permalink
remove avg reref from preprocessing but keep in plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
dungscout96 committed Oct 3, 2023
1 parent cac0150 commit e948ab4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
28 changes: 16 additions & 12 deletions eeg_nemar_preprocess.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
disp(status_tbl)
status = table2array(status_tbl);

splitted = split(EEG.filename(1:end-4),'_');
modality = splitted{end};

fprintf('Running pipeline sequence %s\n', strjoin(opt.pipeline, '->'));
try
for i=1:numel(opt.pipeline)
Expand Down Expand Up @@ -88,18 +91,18 @@
rm_chan_types = {'AUDIO','MEG','EOG','ECG','EMG','EYEGAZE','GSR','HEOG','MISC','PPG','PUPIL','REF','RESP','SYSCLOCK','TEMP','TRIG','VEOG'};
if isfield(EEG.chanlocs, 'type')
EEG = pop_select(EEG, 'rmchantype', rm_chan_types);
types = {EEG.chanlocs.type};
eeg_indices = strmatch('EEG', types)';
if ~isempty(eeg_indices)
EEG = pop_select(EEG, 'chantype', 'EEG');
else
warning("No EEG channel type detected (for first EEG file). Keeping all channels");
end
if strcmp(modality, 'eeg')
types = {EEG.chanlocs.type};
eeg_indices = strmatch('EEG', types)';
if ~isempty(eeg_indices)
EEG = pop_select(EEG, 'chantype', 'EEG');
else
warning("No EEG channel type detected (for first EEG file). Keeping all channels");
end
end
else
warning("Channel type not detected (for first EEG file)");
warning("Channel type not detected (for first recording file)");
end
% ALLEEG = pop_select( ALLEEG,'nochannel',{'VEOG', 'Misc', 'ECG', 'M2'});

status_tbl.remove_chan = 1;
end

Expand All @@ -120,12 +123,12 @@
'LineNoiseCriterion',4,'Highpass',[0.75 1.25] ,'BurstCriterion',20, ...
'WindowCriterion',0.25,'BurstRejection','on','Distance','Euclidian', ...
'WindowCriterionTolerances',[-Inf 7] ,'fusechanrej',1}; % based on Arnaud paper
% ALLEEG = parexec(ALLEEG, 'pop_clean_rawdata', opt.logdir, options{:});
EEG = pop_clean_rawdata( EEG, options{:});

status_tbl.cleanraw = 1;
end

%{
if strcmp(operation, "avg_ref")
if resume && status_tbl.avg_ref
fprintf('Skipping avg_ref\n');
Expand All @@ -138,6 +141,7 @@
status_tbl.avg_ref = 1;
end
%}

if strcmp(operation, "runica")
if resume && status_tbl.runica
Expand All @@ -154,7 +158,7 @@
status_tbl.runica = 1;
end

if strcmp(operation, "iclabel")
if strcmp(operation, "iclabel") && strcmp(modality, 'eeg')
if resume && status_tbl.iclabel
fprintf('Skipping iclabel\n');
continue
Expand Down
12 changes: 11 additions & 1 deletion eeg_nemar_vis.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@

fprintf('Plots: %s\n', strjoin(opt.plots, ', '));

splitted = split(EEG.filename(1:end-4), '_');
modality = splitted{end};

try
for i=1:numel(opt.plots)
plot = opt.plots{i};
Expand All @@ -72,7 +75,7 @@
plot_IC_activation(EEG);
end

if strcmp(plot, 'icmap')
if strcmp(plot, 'icmap') && ~strcmp(modality, 'ieeg')
plot_ICLabel(EEG);
end

Expand Down Expand Up @@ -151,6 +154,10 @@ function plot_spectra(EEG, varargin)
g = finputcheck(varargin, { 'freq' 'integer' [] [6, 10, 22]; ...
'freqrange' 'integer' [] [1 70]; ...
'percent' 'integer' [], 10});

% average reference before plotting
EEG = pop_reref(EEG,[], 'interpchan', []);

% spectopo plot
[spec, freqs] = spectopo(EEG.data, 0, EEG.srate, 'freqrange', g.freqrange, 'title', '', 'chanlocs', EEG.chanlocs, 'percent', g.percent,'plot', 'off');
[~,ind50]=min(abs(freqs-50));
Expand Down Expand Up @@ -180,6 +187,9 @@ function plot_IC_activation(EEG)
error('No IC decomposition found for EEG')
end

% average reference before plotting
EEG = pop_reref(EEG,[], 'interpchan', []);

EEG = pop_icflag(EEG,[0.75 1;NaN NaN;NaN NaN;NaN NaN;NaN NaN;NaN NaN;NaN NaN]);
% IC activations plot
iclocs = EEG.chanlocs;
Expand Down

0 comments on commit e948ab4

Please sign in to comment.