[Eeglablist] Fix for wrong reference channel location

Downey, Ryan J RDowney at bme.ufl.edu
Mon Feb 18 11:31:14 PST 2019

This fix is in response to the post by Li Xiang (https://sccn.ucsd.edu/pipermail/eeglablist/2015/010584.html), titled "Wrong channel location with MNI brain model." I've been meaning to share this for a while. Sorry for the delay. Please let me know if there is a better way to respond specifically to old posts rather than creating a new thread.

Issue: Let's assume 10-5 electrode naming conventions. If you take raw data, use pop_chanedit to append your reference channel as a "nodatchan", then "look up locs" with MNI, and and finally close pop_chanedit, then your original reference channel will have the wrong location.

Cause: the MNI brain is defined with the nose along +Y and in EEGLAB a rotation is applied to data channel locations to align the nose to +X; however, this same rotation isn't applied to "nodatchan" entries (i.e. the reference channel you appended). If you click "plot 3-D (xyz)" immediately after "look up locs", you'll see that the reference channel appears in what seems like the correct location, but note that even though the reference is correct with respect to the locations of all the normal EEG channels, everything is temporarily aligned with nose set to +Y. When you click "ok" to close pop_chanedit, then the function eeg_checkset gets called. Eeg_checkset notices your channels aren't aligned how it prefers (line 1078), and it rotates the chanloc information (lines 1086-1098). In the 2015 post by Li Xiang, the thought was that it was related to adding the reference channel back to the data after average referencing, but with my own tests I can see the reference channel location info is wrong before reaching the re-referencing step.

Fix: add the following code immediately after line 1098 (i.e. after the for loop that goe through all EEG.chanlocs and rotates the location info). The code below is essentially a copy-paste of 1086-1098 but modified for EEG.nodatchans (where your reference location is stored initially).

for index = 1:length(EEG.chaninfo.nodatchans)
    if ~isempty(EEG.chaninfo.nodatchans(index).theta)
        rotategrad = rotate/180*pi;
        coord = (EEG.chaninfo.nodatchans(index).Y + EEG.chaninfo.nodatchans(index).X*sqrt(-1))*exp(sqrt(-1)*-rotategrad);
        EEG.chaninfo.nodatchans(index).Y = real(coord);
        EEG.chaninfo.nodatchans(index).X = imag(coord);
        EEG.chaninfo.nodatchans(index).theta     = EEG.chaninfo.nodatchans(index).theta    -rotate;
        EEG.chaninfo.nodatchans(index).sph_theta = EEG.chaninfo.nodatchans(index).sph_theta+rotate;
        if EEG.chaninfo.nodatchans(index).theta    <-180, EEG.chaninfo.nodatchans(index).theta    =EEG.chaninfo.nodatchans(index).theta    +360; end;
        if EEG.chaninfo.nodatchans(index).sph_theta>180 , EEG.chaninfo.nodatchans(index).sph_theta=EEG.chaninfo.nodatchans(index).sph_theta-360; end;


Ryan J. Downey
Postdoctoral Associate
Human Neuromechanics Laboratory
University of Florida
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://sccn.ucsd.edu/pipermail/eeglablist/attachments/20190218/ac8500df/attachment.html>

More information about the eeglablist mailing list