<div dir="ltr">For completeness, this is what I did in the way you suggest (I think). Note data is downsampled to 100Hz, and every trial is 1 second long. So I do not think that RAM should be a concern (I have about 128 Gig to work with):<div><br></div><div><div><br></div><div>    % load common filter</div><div>    [source_common, leadfield] = WANDER_common_filter_LCMV_MAG(isubject,rootpath,0);</div><div>    </div><div>    % prepare source datastructure</div><div>    source = rmfield(source_common,'avg');</div><div>    source.pow = nan(size(source.pos,1),size(data_MEG_timebinned_append.trial,2),2);</div><div>    source.trialinfo = data_MEG_timebinned_append.trialinfo;</div><div>    </div><div>    for ivoxel = find(source.inside)' </div><div>        disp(['progress: ' round(num2str(ivoxel/size(find(source.inside),1)*100)) '%']);</div><div>        </div><div>        % make timecourse datastructure, clear first so that MATLAB does</div><div>        source_timecourse.trial{size(data_MEG_timebinned_append.trial,2)} = [];</div><div>        source_timecourse.label     = {'voxel'};</div><div>        source_timecourse.fsample   = 100;</div><div>        source_timecourse.time      = data_MEG_timebinned_append.time;</div><div>        for itrial = 1:size(data_MEG_timebinned_append.trial,2)</div><div>            source_timecourse.trial{itrial}  = svdfft(source_common.avg.filter{ivoxel} * data_MEG_timebinned_append.trial{itrial}, 1);</div><div>        end</div><div>        </div><div>        % do mtmconvol on faux data structure</div><div>        cfg                     = [];</div><div>        cfg.channel             = 'all';</div><div>        cfg.method              = 'mtmfft';</div><div>        cfg.keeptrials          = 'yes';</div><div>        cfg.foilim              = [10,11];</div><div>        cfg.taper               = 'hanning';</div><div>        FFT                     = ft_freqanalysis(cfg, source_timecourse);</div><div>        clear source_timecourse</div><div>        source.pow(ivoxel,:,:)  = squeeze(FFT.powspctrm);</div><div>        clear FFT</div><div>        </div><div>        memory</div><div>    end</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 16 November 2017 at 14:40, Stephen Whitmarsh <span dir="ltr"><<a href="mailto:stephen.whitmarsh@gmail.com" target="_blank">stephen.whitmarsh@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Jan-Mathijs,<div><br></div><div>Thanks. In fact, I did what you suggest, but this entails a lot (nr. of positions) or creating and clearing a temporary variable. For a reason I do not understand (but which I encountered before), MATLAB seems not able to deal with this, and runs into memory problems. I suspect it is not able to create and clear many variables in a row, so that althought memory load does not seem to increase, it <i>will </i>break with an out-of-memory problem. I therefor started with this approach, but alas, I now understand that it was a wrong turn. </div><div><br></div><div>So, I am in a pickle now, as neither option works...</div><div><br></div><div>Best,</div><div>Stephen</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 16 November 2017 at 14:31, Schoffelen, J.M. (Jan Mathijs) <span dir="ltr"><<a href="mailto:jan.schoffelen@donders.ru.nl" target="_blank">jan.schoffelen@donders.ru.nl</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Stephen,<br>
<br>
I think that it is currently not possible to pass the output of ft_sourceanalysis to ft_freqanalysis directly, since ft_freqanalysis expects channel-level type data in the input.<br>
The exact details of the computation depend a bit on the amount of RAM you have, and on what exactly you want to achieve.<br>
<br>
If it’s your intention to generate frequency spectra for many dipole locations (e.g. >1000 or so) I would consider the following:<br>
<br>
- compute spatial filters (cfg.keepfilter = ‘yes’);<br>
- use a for-loop across (chunks of) dipole locations to create ‘virtual channel data’, by premultiplying the sensor-level data.trial (loop across trials) with the location specific spatial filter.<br>
- stuff all this into a data-structure that looks like a raw data structure;<br>
- pass this to ft_freqanalysis<br>
<br>
<br>
Alternatively, you could consider using a parcellation approach, if you think it makes sense to reduce the number of spatial locations a bit, although theoretically it should be possible to create a parcellation that consists of just a single dipole per parcel. In this context, you could look into the inner workings of ft_sourceparcellate, which returns a data structure that ft_freqanalysis can work with. Whether ft_sourceparcellate can swallow single trial source data, I am not sure.<br>
<br>
Best wishes,<br>
<br>
JM<br>
<div><div class="m_460568800908248488h5"><br>
<br>
<br>
> On 16 Nov 2017, at 12:36, Stephen Whitmarsh <<a href="mailto:stephen.whitmarsh@gmail.com" target="_blank">stephen.whitmarsh@gmail.com</a>> wrote:<br>
><br>
> Hi FieldTrippers,<br>
><br>
> I was wondering is there is a recommend/most consistent way to represent trial x pos x time data from an LCMV beamformer, also considering the dimord. In other words:<br>
><br>
> with:<br>
><br>
> data.method = 'singletrial'<br>
><br>
> should I use:<br>
><br>
> data.trial{pos} = [rpt x time]<br>
> data.dimord = '{pos}_rpt_time'<br>
><br>
> or rather:<br>
><br>
> data.trial = {pos x rpt x time}<br>
> data.dimord = 'pos_rpt_time'<br>
><br>
> or something else? The purpose is to then do a frequency analysis (with keeptrials = 'yes').<br>
><br>
> Best,<br>
> Stephen<br>
><br>
</div></div>> ______________________________<wbr>_________________<br>
> fieldtrip mailing list<br>
> <a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br>
> <a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/<wbr>mailman/listinfo/fieldtrip</a><br>
<br>
<br>
______________________________<wbr>_________________<br>
fieldtrip mailing list<br>
<a href="mailto:fieldtrip@donders.ru.nl" target="_blank">fieldtrip@donders.ru.nl</a><br>
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" rel="noreferrer" target="_blank">https://mailman.science.ru.nl/<wbr>mailman/listinfo/fieldtrip</a></blockquote></div><br></div>
</div></div></blockquote></div><br></div>