[FieldTrip] dimord single-trial source data

Stephen Whitmarsh stephen.whitmarsh at gmail.com
Thu Nov 16 14:44:36 CET 2017


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):


    % load common filter
    [source_common, leadfield] =
WANDER_common_filter_LCMV_MAG(isubject,rootpath,0);

    % prepare source datastructure
    source = rmfield(source_common,'avg');
    source.pow =
nan(size(source.pos,1),size(data_MEG_timebinned_append.trial,2),2);
    source.trialinfo = data_MEG_timebinned_append.trialinfo;

    for ivoxel = find(source.inside)'
        disp(['progress: '
round(num2str(ivoxel/size(find(source.inside),1)*100)) '%']);

        % make timecourse datastructure, clear first so that MATLAB does
        source_timecourse.trial{size(data_MEG_timebinned_append.trial,2)} =
[];
        source_timecourse.label     = {'voxel'};
        source_timecourse.fsample   = 100;
        source_timecourse.time      = data_MEG_timebinned_append.time;
        for itrial = 1:size(data_MEG_timebinned_append.trial,2)
            source_timecourse.trial{itrial}  =
svdfft(source_common.avg.filter{ivoxel} *
data_MEG_timebinned_append.trial{itrial}, 1);
        end

        % do mtmconvol on faux data structure
        cfg                     = [];
        cfg.channel             = 'all';
        cfg.method              = 'mtmfft';
        cfg.keeptrials          = 'yes';
        cfg.foilim              = [10,11];
        cfg.taper               = 'hanning';
        FFT                     = ft_freqanalysis(cfg, source_timecourse);
        clear source_timecourse
        source.pow(ivoxel,:,:)  = squeeze(FFT.powspctrm);
        clear FFT

        memory
    end

On 16 November 2017 at 14:40, Stephen Whitmarsh <stephen.whitmarsh at gmail.com
> wrote:

> Hi Jan-Mathijs,
>
> 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 *will *break with an out-of-memory problem.
> I therefor started with this approach, but alas, I now understand that it
> was a wrong turn.
>
> So, I am in a pickle now, as neither option works...
>
> Best,
> Stephen
>
> On 16 November 2017 at 14:31, Schoffelen, J.M. (Jan Mathijs) <
> jan.schoffelen at donders.ru.nl> wrote:
>
>> Hi Stephen,
>>
>> 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.
>> The exact details of the computation depend a bit on the amount of RAM
>> you have, and on what exactly you want to achieve.
>>
>> If it’s your intention to generate frequency spectra for many dipole
>> locations (e.g. >1000 or so) I would consider the following:
>>
>> - compute spatial filters (cfg.keepfilter = ‘yes’);
>> - 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.
>> - stuff all this into a data-structure that looks like a raw data
>> structure;
>> - pass this to ft_freqanalysis
>>
>>
>> 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.
>>
>> Best wishes,
>>
>> JM
>>
>>
>>
>> > On 16 Nov 2017, at 12:36, Stephen Whitmarsh <
>> stephen.whitmarsh at gmail.com> wrote:
>> >
>> > Hi FieldTrippers,
>> >
>> > 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:
>> >
>> > with:
>> >
>> > data.method = 'singletrial'
>> >
>> > should I use:
>> >
>> > data.trial{pos} = [rpt x time]
>> > data.dimord = '{pos}_rpt_time'
>> >
>> > or rather:
>> >
>> > data.trial = {pos x rpt x time}
>> > data.dimord = 'pos_rpt_time'
>> >
>> > or something else? The purpose is to then do a frequency analysis (with
>> keeptrials = 'yes').
>> >
>> > Best,
>> > Stephen
>> >
>> > _______________________________________________
>> > fieldtrip mailing list
>> > fieldtrip at donders.ru.nl
>> > https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>>
>>
>> _______________________________________________
>> fieldtrip mailing list
>> fieldtrip at donders.ru.nl
>> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20171116/5c9f4f7d/attachment.html>


More information about the fieldtrip mailing list