<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">This fix is in response to the post by Li Xiang (<a href="https://sccn.ucsd.edu/pipermail/eeglablist/2015/010584.html">https://sccn.ucsd.edu/pipermail/eeglablist/2015/010584.html</a>), 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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><u>Issue</u></b>: 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. <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><u>Cause</u></b>: 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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b><u>Fix</u></b>: 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).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">%%%%%%%%%%%%%%%%%%%<o:p></o:p></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:blue">for</span><span style="font-size:10.0pt;font-family:"Courier New";color:black"> index = 1:length(EEG.chaninfo.nodatchans)</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">   
</span><span style="font-size:10.0pt;font-family:"Courier New";color:blue">if</span><span style="font-size:10.0pt;font-family:"Courier New";color:black"> ~isempty(EEG.chaninfo.nodatchans(index).theta)</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">        rotategrad = rotate/180*pi;</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">        coord = (EEG.chaninfo.nodatchans(index).Y + EEG.chaninfo.nodatchans(index).X*sqrt(-1))*exp(sqrt(-1)*-rotategrad);</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">        EEG.chaninfo.nodatchans(index).Y = real(coord);</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">        EEG.chaninfo.nodatchans(index).X = imag(coord);</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black"></span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">        EEG.chaninfo.nodatchans(index).theta     = EEG.chaninfo.nodatchans(index).theta    -rotate;</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">        EEG.chaninfo.nodatchans(index).sph_theta = EEG.chaninfo.nodatchans(index).sph_theta+rotate;</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">       
</span><span style="font-size:10.0pt;font-family:"Courier New";color:blue">if</span><span style="font-size:10.0pt;font-family:"Courier New";color:black"> EEG.chaninfo.nodatchans(index).theta    <-180, EEG.chaninfo.nodatchans(index).theta    =EEG.chaninfo.nodatchans(index).theta   
 +360; </span><span style="font-size:10.0pt;font-family:"Courier New";color:blue">end</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">;</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">       
</span><span style="font-size:10.0pt;font-family:"Courier New";color:blue">if</span><span style="font-size:10.0pt;font-family:"Courier New";color:black"> EEG.chaninfo.nodatchans(index).sph_theta>180 , EEG.chaninfo.nodatchans(index).sph_theta=EEG.chaninfo.nodatchans(index).sph_theta-360;
</span><span style="font-size:10.0pt;font-family:"Courier New";color:blue">end</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">;</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:black">   
</span><span style="font-size:10.0pt;font-family:"Courier New";color:blue">end</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">;</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:blue">end</span><span style="font-size:10.0pt;font-family:"Courier New";color:black">;</span><span style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal">%%%%%%%%%%%%%%%%%%%<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sincerely,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Ryan J. Downey<o:p></o:p></p>
<p class="MsoNormal">Postdoctoral Associate<o:p></o:p></p>
<p class="MsoNormal">Human Neuromechanics Laboratory<o:p></o:p></p>
<p class="MsoNormal">University of Florida<o:p></o:p></p>
</div>
</body>
</html>