<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=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:"Yu Gothic";
        panose-1:2 11 4 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@Yu Gothic";
        panose-1:2 11 4 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        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;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1400782649;
        mso-list-type:hybrid;
        mso-list-template-ids:512654154 67895313 67895321 67895323 67895311 67895321 67895323 67895311 67895321 67895323;}
@list l0:level1
        {mso-level-text:"%1\)";
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l1
        {mso-list-id:1664241239;
        mso-list-type:hybrid;
        mso-list-template-ids:-2090821608 1791402170 67895299 67895301 67895297 67895299 67895301 67895297 67895299 67895301;}
@list l1:level1
        {mso-level-start-at:62;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-font-family:"Yu Gothic";}
@list l1:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l1:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l1:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l1:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l1:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l1:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l1:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l1:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></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="FR" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Dear FieldTrip community,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-GB">I want to compute coherence between brain sources and an EMG channel that I selected. Here is the pipeline I am using :<o:p></o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l1 level1 lfo1"><span lang="EN-GB">Preprocess MEG and EMG data<o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l1 level1 lfo1"><span lang="EN-GB">Process single subject MRI data to get (a) the head model, (b) the source model with leadfields<o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l1 level1 lfo1"><span lang="EN-GB">Reconstruct MEG data using beamformer techniques in the time domain.
<o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l1 level1 lfo1"><span lang="EN-GB">Compute coherence between source data and EMG data<o:p></o:p></span></li></ul>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">To be able to compute coherence, I need to reconstruct data for all trials and not as an average of trials. But I encountered a problem at this level.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Here is the code I used first :<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% Compute noise-covariance matrix
</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">    cfg            = [];</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 lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">cfg.covariance =
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#A020F0">'yes'</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">;
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">%default takes the whole time window to estimate the noise covariance matrix</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.keeptrials =
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#A020F0">'yes'</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">;</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">   
</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    tlcontr_MEG    = ft_timelockanalysis(cfg, MEG_contr);</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">   
</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% Compute inverse modelling with mne : source data averaged over</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% trails</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg                = [];</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.method         =
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#A020F0">'mne'</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">;</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.sourcemodel    = leadfield;</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.headmodel      = headmodel;</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.mne.lambda     = 3;
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">%%????</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.mne.keepfilter =
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#A020F0">'yes'</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">;</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.rawtrial       =
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#A020F0">'no'</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">;</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">   
</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    source_MEG_contr   = ft_sourceanalysis(cfg,tlcontr_MEG);</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% Get source data for all trials : project trials by hand
</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    FILTER = source_MEG_contr.avg.filter(cellfun(@(a) ~isempty(a),source_MEG_contr.avg.filter));</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">   </span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:blue">for</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">
 triali = 1 : length(MEG_contr.trial)</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">        source_MEG_contr_trials.pow{triali} = cell2mat(cellfun(@(a) sum((a*MEG_contr.trial{triali}).^2,1),FILTER,</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#A020F0">'UniformOutput'</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">,false)');</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">        disp([</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#A020F0">'Trial n° '</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">
 num2str(triali) </span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#A020F0">' out of '</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black"> num2str(length(MEG_contr.trial))])</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">       
</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    </span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:blue">end</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">source_MEG_contr_trials</span><span lang="EN-GB">  is to be the structure that contains source data for all trials. As you can see I computed it by hand,
 following a thread that I found on the website. <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Then I found it was possible to use ft_sourceanalysis again, to project all trials through the filter computed at the first use of the function. So I replaced the last paragraph of code with the following :<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">   
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% project all trials through common spatial filter to get source data</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">   
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% for separate trials</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg=[];</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.method             =
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#A020F0">'mne'</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">;</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.sourcemodel        = leadfield;      
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% previously computed grid</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.headmodel          = headmodel;       
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% previously computed volume conduction model</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.rawtrial           =
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#A020F0">'yes'</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">;     
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% project each single trial through the filter to reconstruct single trial data</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">   
</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    cfg.sourcemodel.filter = source_MEG_contr.avg.filter;
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% use the common filter computed in the previous step!</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">    source_MEG_contr_trials      = ft_sourceanalysis(cfg, tlcontr_MEG);
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:#34C03C">% contains the source estimates for all trials/both conditions</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I preferred this “automatic” way rather than the manual one because it allows me to keep the FieldTrip shape of structures more easily and display results using FieldTrip functions.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">However, I realized that it returned completely different results. After trying to understand the steps performed in the second use of ft_sourceanalysis, I realized that filters used to compute trial source data from
 trial channel data (l. 295 in ft_inverse_mne of fieldtrip-20210921 : <b>estimate.mom{i} = sourcemodel.filter{i}*dat</b>) were different from filters in cfg.sourcemodel.filter.  <br>
In fact, channel labels are taken from the leadfield structure. Lines (channel dimension) in filter matrices (in cfg.sourcemodel.filter) are reorganized so that it matches channel order from data.label (= tlcontr_MEG.label).
<br>
See l.404-410 in ft_sourceanalysis of fieldtrip-20210921 : <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">[dum, chansel] = match_str(data.label, sourcemodel.label);</span><span lang="EN-GB"><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">sourcemodel.label = sourcemodel.label(chansel);<o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:blue">for</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black"> i=1:numel(sourcemodel.filter)</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">  
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:blue">if</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black"> ~isempty(sourcemodel.filter{i})</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">     sourcemodel.filter{i} = sourcemodel.filter{i}(:, chansel);</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:black">  
</span><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:blue">end</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:10.0pt;font-family:"Courier New";color:blue">end</span><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal" style="text-autospace:none"><span lang="EN-GB" style="font-size:12.0pt;font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Thus, if I understand it correctly, this step assumes that lines in filter matrices (which come from source_MEG_contr structure) are organized in the same way as channels in leadfields. However, this is not actually the
 case here because<o:p></o:p></span></p>
<ol style="margin-top:0cm" start="1" type="1">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo2"><span lang="EN-GB">source_MEG_contr.avg.label and data.label (= tlcontr_MEG.label) are equal.  <o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo2"><span lang="EN-GB">I don’t understand why but leadfields.label is different from the original alphanumerical channel organization – A1 A2 A3 etc…- found in raw data (as well as in
 source_MEG_contr, and in tlcontr_MEG).<o:p></o:p></span></li></ol>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">So I think that in my case, lines in filter matrices should not be reorganized (when they are not, I get the same results as by hand) but as leadfield structure is also used when I compute source_MEG_contr from tlcontr_MEG,
 I am not sure I can trust source_MEG_contr either. <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I would truly appreciate if someone could proofread and pinpoint some problems in this reasoning to help me solve this annoying problem. In the meantime I will try to recompute the leadfield structure so that channel
 order is the same everywhere. <o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Thank you in advance for your help and the time you will spend reading through this message!
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal">Manon Châteaux<o:p></o:p></p>
<p class="MsoNormal">phD Student at Aix-Marseille University<o:p></o:p></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"><o:p> </o:p></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"><o:p> </o:p></p>
</div>
</body>
</html>