EEGLAB Code for Retaining Online Reference Electrode

Hi EEG researchers,
I am conducting an N400 analysis on EEG data collected with a 32-channel BrainVision system using Cz as the online reference. As a result, Cz is not present in the recorded data. However, because my study requires analyzing the N400 at Cz, I need to reconstruct and retain this channel before re-referencing.
In my dataset, there are 31 scalp electrodes (channels 1–31) and 2 EOG electrodes (channels 32–33). Cz was not recorded as a data channel. In the code below, I manually add Cz back as a new channel (appended as the last channel in chanlocs) using standard location information, and then re-reference the data to the left and right mastoids (channels 10 and 21), excluding the EOG channels.
I would greatly appreciate any feedback on whether this approach is methodologically and technically appropriate. Thank you all!
%% Re-referencing
EEG = eeg_checkset( EEG );
% add Cz back to data
EEG.nbchan = EEG.nbchan + 1;
EEG.data(end+1,:,:) = 0;
EEG.chanlocs(end+1).labels = 'Cz';
tmpl = readlocs('/Users/xxxx/eeglab2025.1.0/plugins/dipfit/standard_BEM/elec/standard_1005.elc');
idxCz = find(strcmpi({tmpl.labels}, 'Cz'), 1);
EEG.chanlocs(end).X = tmpl(idxCz).X;
EEG.chanlocs(end).Y = tmpl(idxCz).Y;
EEG.chanlocs(end).Z = tmpl(idxCz).Z;
EEG.chanlocs(end).theta = tmpl(idxCz).theta;
EEG.chanlocs(end).radius = tmpl(idxCz).radius;
EEG.chanlocs(end).sph_theta = tmpl(idxCz).sph_theta;
EEG.chanlocs(end).sph_phi = tmpl(idxCz).sph_phi;
EEG.chanlocs(end).sph_radius = tmpl(idxCz).sph_radius;
% re-referencing to mastroids, 32 33 are eye electrodes
EEG = pop_reref( EEG, [10 21] ,'exclude',[32 33],'keepref','on'); % still keep the ref channel in data scroll
EEG.setname = 'refed_enc';
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET + 1,'gui','off');
eeglab redraw;

Answers (0)

Categories

Asked:

about 20 hours ago

Edited:

about 20 hours ago

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!