<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="">
Hi Benjy,
<div class=""><br class="">
</div>
<div class="">I would recommend against using the ‘rawtrial’ option. This in retrospect is a poorly implemented functionality in FieldTrip and does not work well (if at all) in concrete situations.</div>
<div class=""><br class="">
</div>
<div class="">I would recommend to use ft_virtualchannel to obtain your single trial time courses. I think that this has been discussed at other threads in this discussion forum, so it should be possible to find some information about this.</div>
<div class=""><br class="">
</div>
<div class="">Also, if your intention is to be able to classify zero from notzero trials, you will probably fool yourself if you NOT compute the covariance across all trials combined, and do a single call to ft_sourceanalysis to obtain a set of common spatial
 filters. Currently, your pasted code computes the covariance and spatial filters per condition, which will already serve as a booster to make the 2 conditions more dissimilar.</div>
<div class=""><br class="">
</div>
<div class="">Good luck,</div>
<div class="">Jan-Mathijs</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class="">
<div>
<blockquote type="cite" class="">
<div class="">On 25 Apr 2023, at 14:32, 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=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Sorry
 for multiple posting, please ignore - I have just noticed the cfg.rawtrials option in ft_sourceanalysis, which makes this much simpler.</span>
<div class="" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<br class="">
</div>
<div class="" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
Thank you<br class="">
<div class=""><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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
<div class="" style="background-color: rgb(255, 239, 213); padding: 1px;">
<p class="" style="font-size: 11pt; line-height: 10pt; font-family: Arial, Helvetica, sans-serif;">
⚠ 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 class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; color: rgb(2, 128, 9);">
    % Compute Covariance Matrix</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg = [];</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.covariance =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 4, 249);">'yes'</span>;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    avg = ft_timelockanalysis(cfg,meg_data); %meg_data = datazero + datanotzero;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; min-height: 13px;">
    <br class="webkit-block-placeholder">
</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.keeptrials =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 4, 249);">'yes'</span>;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    avgzero = ft_timelockanalysis(cfg,datazero); %condition 1 = ‘zero'</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    avgnotzero = ft_timelockanalysis(cfg,datanotzero); %condition 2 = ’not zero'</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; min-height: 13px;">
    <br class="webkit-block-placeholder">
</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; color: rgb(2, 128, 9);">
<span class="">   <span class="Apple-converted-space"> </span></span>%Calculate spatial filter for each voxel over all data</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg = [];</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.method =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 4, 249);">'lcmv'</span>;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.sourcemodel = sourcemodel_new;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.headmodel = headmodel_new;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.lcmv.keepfilter =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 4, 249);">'yes'</span>;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.lcmv.lambda =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 4, 249);">'5%'</span>;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.lcmv.weightnorm =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 4, 249);">'unitnoisegain'</span>;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.lcmv.fixedori =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 4, 249);">'yes'</span>;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.channel = {<span class="" style="color: rgb(170, 4, 249);">'MEG'</span>};</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.senstype =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 4, 249);">'MEG'</span>;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    sourceavg = ft_sourceanalysis(cfg, avg); %compute filters over all trials</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; min-height: 13px;">
    <br class="webkit-block-placeholder">
</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier; color: rgb(2, 128, 9);">
<span class="">   <span class="Apple-converted-space"> </span></span>%Now apply this filter to zero and not-zero data separately</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg = [];</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.method =<span class="Apple-converted-space"> </span><span class="" style="color: rgb(170, 4, 249);">'lcmv'</span>;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.sourcemodel = sourcemodel_new;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.sourcemodel.filter = sourceavg.avg.filter;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    cfg.headmodel = headmodel_new;</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    sourcezero = ft_sourceanalysis(cfg, avgzero);</div>
<div class="" style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Courier;">
    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$" class="">https://doi.org/10.1371/journal.pcbi.1002202</a><br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">_______________________________________________</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">fieldtrip
 mailing list</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">
<a href="https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!9VKw5aAkcqyFPaSPE2qsPhnkgzk6tmjf-ll1wgLUr-bAskClg_DnP0eVgOlsbQ8Ez8ewmq9_2rsSSisJDFRupORjwY_Y-1owr6Dtww$" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!9VKw5aAkcqyFPaSPE2qsPhnkgzk6tmjf-ll1wgLUr-bAskClg_DnP0eVgOlsbQ8Ez8ewmq9_2rsSSisJDFRupORjwY_Y-1owr6Dtww$</a><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""></span></div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>