<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Sorry for multiple posting, please ignore - I have just noticed the cfg.rawtrials option in ft_sourceanalysis, which makes this much simpler.
<div class=""><br class="">
</div>
<div class="">Thank you<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On Apr 25, 2023, at 1:12 PM, Barnett, Benjy via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl" class="">fieldtrip@science.ru.nl</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div style="background-color:#FFEFD5; padding:1px; " class="">
<p style="font-size:11pt; line-height:10pt; font-family: 'Arial','Helvetica',sans-serif;" class="">
⚠ Caution: External sender</p>
</div>
<br class="">
<div class="">Hi all,
<div class=""><br class="">
</div>
<div class="">I’m trying to implement some MVPA decoding analyses in source space using MEG data collected on a CTF system. I have gone through different tutorials to perform the source reconstruction (namely <a href="https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/workshop/aarhus/beamformingerf/__;!!HJOPV4FYYWzcc1jazlU!6dJY9xn9eTEqqGoXULa_OMBzAvS3Cl7jDWxpxhESR-a61x1hEJWt38h4sKsVfLMoG9DIkPTj6qamNi18fKgf9dtYDIaRLfHvTw$" originalsrc="https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/workshop/aarhus/beamformingerf/__;!!HJOPV4FYYWzcc1jazlU!6dJY9xn9eTEqqGoXULa_OMBzAvS3Cl7jDWxpxhESR-a61x1hEJWt38h4sKsVfLMoG9DIkPTj6qamNi18fKgf9dtYDIaRLfHvTw$" shash="MWnbUqcyEpfb4w24mz60KcGzika8gzLbc572WrUlUGpIWZIftBXjI8vHfh/UT9VUKNDC1/BJwEkbZt/ASHJjmRFeuYXv++UF7K+nQTHDa0tVk3hGWukxV318Z2ZnmgH4nVWj2yrrT9GMTNi1RQI+AHp0OaXYo7uo53PW1pOjKfY=" class="">https://www.fieldtriptoolbox.org/workshop/aarhus/beamformingerf/</a>; <a href="https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/workshop/paris2019/handson_sourceanalysis/__;!!HJOPV4FYYWzcc1jazlU!6dJY9xn9eTEqqGoXULa_OMBzAvS3Cl7jDWxpxhESR-a61x1hEJWt38h4sKsVfLMoG9DIkPTj6qamNi18fKgf9dtYDIZKqhJFug$" originalsrc="https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/workshop/paris2019/handson_sourceanalysis/__;!!HJOPV4FYYWzcc1jazlU!6dJY9xn9eTEqqGoXULa_OMBzAvS3Cl7jDWxpxhESR-a61x1hEJWt38h4sKsVfLMoG9DIkPTj6qamNi18fKgf9dtYDIZKqhJFug$" shash="mmBfn/R2kyCqGi6D0mQIdxSAF1JpioWHFVb7s9XAqReNNLndhwQVB4yg983D962qgtYjPAoKHVPfPllVM6x1h76XLWXHkeI6YS10bRGq0TcDjy6jIG5NHu1ettLEXXCw44+37Ec3338hxQ/Xn5aPbTHSP8SmglVFzedmf1aMTiE=" class="">https://www.fieldtriptoolbox.org/workshop/paris2019/handson_sourceanalysis/</a>).</div>
<div class=""><br class="">
</div>
<div class="">To train my decoder, I will obviously need trial by trial activity estimates for each of the virtual channels. The issue is that these tutorials, and most other information I can find, only go into how to extract condition-level source estimates.
 I have an idea of how to do this for individual trials, but it’s such a shift from the tutorials I wondered if I could check whether my plan will work conceptually and technically. </div>
<div class=""><br class="">
</div>
<div class="">My current code (to obtain condition level estimates) is as follows:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; color: rgb(2, 128, 9);" class="">
    % Compute Covariance Matrix</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg = [];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.covariance = <span style="color: #aa04f9" class="">'yes'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    avg = ft_timelockanalysis(cfg,meg_data); %meg_data = datazero + datanotzero;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; min-height: 13px;" class="">
    <br class="webkit-block-placeholder">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.keeptrials = <span style="color: #aa04f9" class="">'yes'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    avgzero = ft_timelockanalysis(cfg,datazero); %condition 1 = ‘zero'</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    avgnotzero = ft_timelockanalysis(cfg,datanotzero); %condition 2 = ’not zero'</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; min-height: 13px;" class="">
    <br class="webkit-block-placeholder">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; color: rgb(2, 128, 9);" class="">
<span style="" class="">    </span>%Calculate spatial filter for each voxel over all data</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg = [];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.method = <span style="color: #aa04f9" class="">'lcmv'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.sourcemodel = sourcemodel_new;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.headmodel = headmodel_new;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.lcmv.keepfilter = <span style="color: #aa04f9" class="">'yes'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.lcmv.lambda = <span style="color: #aa04f9" class="">'5%'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.lcmv.weightnorm = <span style="color: #aa04f9" class="">'unitnoisegain'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.lcmv.fixedori = <span style="color: #aa04f9" class="">'yes'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.channel = {<span style="color: #aa04f9" class="">'MEG'</span>};</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.senstype = <span style="color: #aa04f9" class="">'MEG'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    sourceavg = ft_sourceanalysis(cfg, avg); %compute filters over all trials</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; min-height: 13px;" class="">
    <br class="webkit-block-placeholder">
</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; color: rgb(2, 128, 9);" class="">
<span style="" class="">    </span>%Now apply this filter to zero and not-zero data separately</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg = [];</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.method = <span style="color: #aa04f9" class="">'lcmv'</span>;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.sourcemodel = sourcemodel_new;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.sourcemodel.filter = sourceavg.avg.filter;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    cfg.headmodel = headmodel_new;</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    sourcezero = ft_sourceanalysis(cfg, avgzero);</div>
<div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;" class="">
    sourcenotzero = ft_sourceanalysis(cfg, avgnotzero);</div>
</div>
<div class=""><br class="">
</div>
<div class="">Would I be correct to simply alter this pipeline so that I perform the call to ft_timelockanalysis and estimate the covariance matrix for each trial individually, rather than each condition? Then I was planning to simply run the ft_sourceanalysis
 function on each of these trials individually, keeping track of which trial belongs to which condition for later use in decoding. I can then go into the source output from the sourceanalysis and extract the .mom field to get the virtual channel data per trial,
 which I plan to then enter into the decoder.</div>
<div class=""><br class="">
</div>
<div class="">Does this make sense conceptually? It seems a logical step from the beamforming of condition level signals, but I’ve come to learn it’s rarely that simple!</div>
<div class=""><br class="">
</div>
<div class="">I hope that all makes sense,</div>
<div class=""><br class="">
</div>
<div class="">Benjy</div>
</div>
</div>
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
<a href="https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!4HiCPnTY4ZHLBQO-35S-qTzf4nEOOD1IKhyJGLDYrHsrcjodns47ZrpV1HfVBgHidCK45KCLe79g6tzsGhQWqnFMt5BvVIyIiw$">https://doi.org/10.1371/journal.pcbi.1002202</a><br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>