<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Thank you very much Vahab! </div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
In the end we managed to create a good leadfield model by computing our own headmodel instead of loading a Fieldtrip one. Our scale is lower than the the one shown in the tutorial but the leadfield looks ok!</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I am going to get back to your answer in the future and try to use SPM for the forward model. Indeed, I hope your answer is going to be useful to other users as well!</div>
<div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div></div>
<div></div>
<div id="divtagdefaultwrapper" dir="ltr" style="font-size:12pt; color:#000000; font-family:Calibri,Helvetica,sans-serif">
<div style="margin-top:0px; margin-bottom:0px; margin-top:0; margin-bottom:0">
<div dir="ltr" style="margin:0px; font-family:Calibri,Helvetica,sans-serif; font-size:12pt">
<div style="margin:0px; font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px; color:rgb(33,33,33)">
<div style="margin:0px">
<div style="margin:0px">
<p style="margin:0in 0in 0.0001pt"><span style="color: black; font-size: 12pt;">Best wishes.</span><br>
</p>
<p style="margin:0in 0in 0.0001pt"><span style="margin:0px; font-size:12pt; color:black"><br>
</span></p>
<p style="margin:0in 0in 0.0001pt"><span style="margin:0px; font-size:12pt; color:black"><br>
</span></p>
<p style="margin:0in 0in 0.0001pt"><span style="margin:0px; font-size:12pt; color:black">Elisa </span></p>
<p style="margin:0in 0in 0.0001pt"><span style="margin:0px; font-size:12pt; color:black"><br>
Elisa Tatti, Ph.D</span></p>
<p style="margin:0in 0in 0.0001pt"><span style="margin:0px; font-size:12pt; color:black">Post Doctoral Research Fellow </span><span style="margin:0px; font-family:"Times New Roman",serif,serif,EmojiFont; font-size:12pt"><u></u><u></u></span></p>
</div>
<div style="margin:0px">
<p style="margin:0in 0in 0.0001pt"><span style="color:black; font-size:12pt">CUNY, School of Medicine </span><br>
</p>
</div>
<div style="margin:0px">
<p style="margin:0in 0in 0.0001pt"><span style="margin:0px; font-size:12pt; color:black">160 Convent ave</span><span style="margin:0px; font-family:"Times New Roman",serif,serif,EmojiFont; font-size:12pt"><u></u><u></u></span></p>
</div>
<div style="margin:0px">
<p style="margin:0in 0in 0.0001pt"><span style="margin:0px; font-size:12pt; color:black">10031 </span><span style="margin:0px; font-family:"Times New Roman",serif,serif,EmojiFont; font-size:12pt"><u></u><u></u></span></p>
</div>
<div style="margin:0px">
<p style="margin:0in 0in 0.0001pt"><span style="margin:0px; font-size:12pt; color:black">New York City, NY </span><span style="margin:0px; font-family:"Times New Roman",serif,serif,EmojiFont; font-size:12pt"><u></u><u></u></span></p>
</div>
<div style="margin:0px">
<p style="margin:0in 0in 0.0001pt"><span style="margin:0px; font-size:12pt; color:black"> </span><span style="margin:0px; font-family:"Times New Roman",serif,serif,EmojiFont; font-size:12pt"><u></u><u></u></span></p>
</div>
</div>
</div>
<p style="margin:0in 0in 0.0001pt; color:rgb(33,33,33); font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont; font-size:15px">
<span style="margin:0px; font-size:12pt; color:black">Tel. +1 3472043952</span></p>
</div>
<div style="margin:0px">
<div style="margin:0px; color:rgb(51,51,51); text-align:start"></div>
<br>
</div>
<br>
<br>
</div>
</div>
</div>
</div>
<div>
<div id="appendonsend"></div>
<div style="font-family:Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>Da:</b> Youssofzadeh, Vahab <vyoussofzadeh@mcw.edu><br>
<b>Inviato:</b> giovedì 10 dicembre 2020 13:24<br>
<b>A:</b> Elisatatti@msn.com <Elisatatti@msn.com><br>
<b>Oggetto:</b> EEG source analysis Leadfield issue</font>
<div> </div>
</div>
<div lang="EN-GB" style="word-wrap:break-word">
<div class="x_WordSection1">
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt">Hi Elisa,</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt">I saw your post in the FT community, I am no expert by all means in EEG source modeling, however, I had a similar issue with a hdEEG dataset I was working on 2 years ago. I thought these scripts might be helpful. For forwarding
modeling and channel alignment, I used SPM, and I found it superior to FT functions. It is a bit mess, hope you can grab the required details (eg, you can comment the spm beamforming part),</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt"> </span></p>
<p class="x_p1" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New"; color: forestgreen;">
<span class="x_apple-converted-space"> </span>%% forward model from SPM</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>outputdir1 = fullfile(outputdir,
<span class="x_s1" style="color: rgb(160, 32, 240);">'spm_source'</span>);</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>cd(outputdir1);</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>name = [<span class="x_s1" style="color: rgb(160, 32, 240);">'m'</span>,subj,<span class="x_s1" style="color: rgb(160, 32, 240);">'_'</span>,run];</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span><span class="x_s2" style="color: blue;">if</span> exist([name,<span class="x_s1" style="color: rgb(160, 32, 240);">'.mat'</span>],
<span class="x_s1" style="color: rgb(160, 32, 240);">'file'</span>) == 2</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>D = spm_eeg_load(name);</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span><span class="x_s2" style="color: blue;">else</span></p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>cfg = [];</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>cfg.toilim = [-0.4 1];</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>eint_data = ft_redefinetrial(cfg, data);</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>vy_source_spm(eint_data,mridir,name);</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>D = spm_eeg_load(name);</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span><span class="x_s2" style="color: blue;">end</span></p>
<p class="x_p1" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New"; color: forestgreen;">
% <span class="x_apple-converted-space"> </span>cd(outputdir)</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>volsens = spm_eeg_inv_get_vol_sens(D, 1,
<span class="x_s1" style="color: rgb(160, 32, 240);">'MNI-aligned'</span>, <span class="x_s1" style="color: rgb(160, 32, 240);">
'inv'</span>, <span class="x_s1" style="color: rgb(160, 32, 240);">'EEG'</span>);</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>clear <span class="x_s1" style="color: rgb(160, 32, 240);">
D</span></p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>vol = volsens.EEG.vol;</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>sens = volsens.EEG.sens;</p>
<p class="x_p3" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span></p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>vol = ft_convert_units(vol,<span class="x_s1" style="color: rgb(160, 32, 240);">'mm'</span>);</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>sens = ft_convert_units(sens,<span class="x_s1" style="color: rgb(160, 32, 240);">'mm'</span>);</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>[vol, sens] = ft_prepare_vol_sens(vol, sens,
<span class="x_s1" style="color: rgb(160, 32, 240);">'channel'</span>, data.label');</p>
<p class="x_p2" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New";">
<span class="x_apple-converted-space"> </span>grid = vy_leadfield_eeg(sens, vol);</p>
<p class="x_p1" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New"; color: forestgreen;">
<span class="x_apple-converted-space"><span style="color:black"> </span></span>%
<span class="x_apple-converted-space"> </span>figure; ft_plot_vol(vol, 'edgecolor', 'none', 'facealpha', 0.2); camlight;</p>
<p class="x_p1" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New"; color: forestgreen;">
<span class="x_apple-converted-space"><span style="color:black"> </span></span>%
<span class="x_apple-converted-space"> </span>hold on</p>
<p class="x_p1" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New"; color: forestgreen;">
<span class="x_apple-converted-space"><span style="color:black"> </span></span>%
<span class="x_apple-converted-space"> </span>ft_plot_mesh(grid.pos(grid.inside, :));</p>
<p class="x_p1" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New"; color: forestgreen;">
<span class="x_apple-converted-space"><span style="color:black"> </span></span>%
<span class="x_apple-converted-space"> </span>view([-45 20]);</p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:blue">function</span><span style="font-size:7.5pt; font-family:"Courier New""> vy_source_spm(int_data,mridir,subj)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% initial settings</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% restoredefaultpath</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:black">spm_path = </span>
<span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0">'F:\My Matlab\SPM\spm12_4\spm12\spm12'</span><span style="font-size:7.5pt; font-family:"Courier New"; color:black">;</span><span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0"></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">addpath(genpath(spm_path))</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%%</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_ft2spm(int_data, subj);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% Avergaring</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% datafile3 = ['.\aefspmeeg_',name];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% S = [];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% S.D = name;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% S.robust = false;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% S.prefix = 'm';</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D = spm_eeg_average(S);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% % spm_eeg_review(D)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D = spm_eeg_load(datafile3);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_review(D)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% Re-ref</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% S = [];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% S.D = D;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% S.refchan = 'average';</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% [D, ~] = spm_eeg_reref_eeg(S);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_review(D)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% adding layout, elec pos</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:black">layout = </span>
<span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0">'F:\My Matlab\My codes\My GitHub\fieldtrip_041718\fieldtrip-master\template\electrode\GSN-HydroCel-256.sfp'</span><span style="font-size:7.5pt; font-family:"Courier New"; color:black">;</span><span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0"></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S = [];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.D = D;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:black">S.task = </span>
<span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0">'loadeegsens'</span><span style="font-size:7.5pt; font-family:"Courier New"; color:black">;</span><span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0"></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.source = <span style="color:#A020F0">
'locfile'</span>;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.sensfile = layout;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_prep(S);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_review(D)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% Create 2D channel layout</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S = [];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:black">S.task = </span>
<span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0">'project3D'</span><span style="font-size:7.5pt; font-family:"Courier New"; color:black">;</span><span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0"></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.modality = <span style="color:#A020F0">
'EEG'</span>;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.updatehistory = 1;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.D = D;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_prep(S);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_review(D)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%%</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:black">path_montage =
</span><span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0">'F:\My Matlab\My codes\My scripts\UTHSC\hd-EEG\My scripts\SPM analysis\Data_file'</span><span style="font-size:7.5pt; font-family:"Courier New"; color:black">;</span><span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0"></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S = [];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.D = D;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.task = <span style="color:#A020F0">
'montage'</span>;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.montagefile = {fullfile(path_montage,<span style="color:#A020F0">'Data_file/montage'</span>)};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.keepothers = 0;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% S.montage.mode.write.blocksize = 655360;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.prefix = <span style="color:#A020F0">
'g'</span>;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_prep(S);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_review(D)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% mri segmentation & mesh generation</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">sMRI = fullfile(mridir,[subj,<span style="color:#A020F0">'_T1.nii'</span>]);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:blue">if</span><span style="font-size:7.5pt; font-family:"Courier New""> exist(sMRI,
<span style="color:#A020F0">'file'</span>) ~= 2</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:black"> sMRI = </span>
<span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0">'F:\My Matlab\SPM\spm12_4\spm12\spm12\canonical\single_subj_T1.nii'</span><span style="font-size:7.5pt; font-family:"Courier New"; color:black">;</span><span style="font-size:7.5pt; font-family:"Courier New"; color:#A020F0"></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:blue">end</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">Msize = 2; val = 1;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_inv_mesh_ui(D, val, sMRI, Msize);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_review(D)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% Coreg</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">selection = 1:3;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">eegfid = D.fiducials;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">eegfid.fid.pnt = eegfid.fid.pnt(selection, :);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">eegfid.fid.label = eegfid.fid.label(selection);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">newmrifid = D.inv{val}.mesh.fid;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">newmrifid.fid.pnt = D.inv{val}.mesh.fid.fid.pnt(1:3,:);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">newmrifid.fid.label = {<span style="color:#A020F0">'FidNz'</span>;<span style="color:#A020F0">'FidT9'</span>;<span style="color:#A020F0">'FidT10'</span>};
<span style="color:forestgreen">%{'Nasion';'LPA';'RPA'};</span></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">useheadshape = 1;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_inv_datareg_ui(D, val, eegfid, newmrifid, useheadshape);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.prefix = <span style="color:#A020F0">
'e'</span>;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D = spm_eeg_inv_datareg_ui(D);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% forward modelling</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{1}.forward(1).voltype =
<span style="color:#A020F0">'EEG BEM'</span>;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_inv_forward(D);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">spm_eeg_inv_checkforward(D,1);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D = spm_eeg_inv_forward_ui(D);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_review(D)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% source BF</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% datafile = ['.\e',name];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D = spm_eeg_load(datafile);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S = [];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.D = D;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.trigger{1} = {<span style="color:#A020F0">'Undefined'</span>};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.timewindows{1}=[.4;.7];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.timewindows{2}=[-.3;0];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.trigger{2} = {<span style="color:#A020F0">'Undefined'</span>};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.freqbands{1} = [2,30];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.gridstep = 6;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.regpc = 10;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.preview = 1;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">spm_eeg_ft_beamformer_gui(S);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% Avergaring</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S = [];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.D = D;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.robust = false;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">S.prefix = <span style="color:#A020F0">
'm'</span>;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_average(S);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_review(D)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">%% source task</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% inv_typ = 'GS';% 'GS'; %'COH'; % (MSP)%inv_typ = 'IID'; % Minimum Norm Least-Squares</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">inv_typ = <span style="color:#A020F0">
'COH'</span>; <span style="color:forestgreen">% Loreta</span></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">woi = [-400 999];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.inverse = [];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.inverse.type = inv_typ;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.inverse.lpf = 0.1;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.inverse.hpf = 48;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.inverse.woi = woi;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.inverse.Han = 1;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.inverse.modality = {<span style="color:#A020F0">'eeg'</span>};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_invert(D);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">woi1 = [400,700];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">con_win = {woi1; 0};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.contrast.woi = con_win{1};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.contrast.fboi = con_win{2};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.contrast.type =
<span style="color:#A020F0">'evoked'</span>;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_inv_results(D);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">savepath = [<span style="color:#A020F0">'t'</span>,num2str(con_win{1}(1)),<span style="color:#A020F0">'_'</span>,num2str(con_win{1}(2))];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">hcp_write_figure([savepath,<span style="color:#A020F0">'.png'</span>], gcf,
<span style="color:#A020F0">'resolution'</span>, 300);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.contrast.smooth = 12;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.inv{val}.contrast.format = {<span style="color:#A020F0">'image'</span>};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D = spm_eeg_inv_Mesh2Voxels(D);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_inv_imag_api</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% inv_typ = 'COH'; % Loreta</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% woi = [-400 999];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.inverse = [];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.inverse.type = inv_typ;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.inverse.lpf = 0;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.inverse.hpf = 48;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.inverse.woi = woi;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.inverse.Han = 1;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.inverse.modality = {'eeg'};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D = spm_eeg_invert(D);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% con_win = {woi; 0};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.contrast.woi = con_win{1};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.contrast.fboi = con_win{2};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.contrast.type = 'evoked';</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D = spm_eeg_inv_results(D);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.contrast.smooth = 12;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.inv{val}.contrast.format = {'image'};</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D = spm_eeg_inv_Mesh2Voxels(D);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D.save</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% D = spm_eeg_invert_ui(D);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_inv_imag_api</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% spm_eeg_inv_imag_api(D)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_p1" style="margin: 0cm; font-size: 7.5pt; font-family: "Courier New"; color: forestgreen;">
<span style="color:blue">function</span><span style="color:windowtext"> leadfield_eeg = vy_leadfield_eeg(elec, vol)</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% begin with leadfield computation</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% clear grid</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">cfg = [];</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">cfg.elec = elec;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">cfg.headmodel = vol;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">cfg.reducerank = 3;</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">cfg.grid.resolution = 12;
<span style="color:forestgreen">% specified in mm</span></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen">% cfg.grid.tight = 'yes';</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"">leadfield_eeg = ft_prepare_leadfield(cfg);</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:9.0pt; font-family:"Courier New""> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:7.5pt; font-family:"Courier New"; color:forestgreen"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt">I wasn’t confident to share this with the community
</span><span style="font-size:11.0pt; font-family:"Apple Color Emoji"">😃</span><span style="font-size:11.0pt"></span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt">Let me know if you need more details or had any questions.</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt">Best,</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt">Vahab</span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt"> </span></p>
<p class="x_MsoNormal" style="margin: 0cm; font-size: 12pt; font-family: Calibri, sans-serif;">
<span style="font-size:11.0pt"> </span></p>
</div>
</div>
</div>
</body>
</html>