[FieldTrip] Trials are not averaging

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Thu Aug 10 14:03:22 CEST 2023


Hi Selena,

I don’t understand why you think you need to call ft_definetrial when using data that seems to be in  a matlab mat-file. I would assume that the P24DR_rawdata.mat file contains already a fieldtrip compatible data structure with one or more ’trials’ in the data.trial field.

Also, if you call ft_preprocessing with already a data structure in the input (which you seem to do), the cfg.trl which may have been computed (either correctly or incorrectly) will not be applied to the input data object. The cfg.trl field will only apply if you are reading (raw) data from disk directly.

If you want to chop up a long continuous data recording that you have already loaded into memory, you should not use ft_definetrial, but rather you should use ft_redefinetrial.

Also, of note, if you want to compute a meaningful connectivity using FieldTrip, you will need more than a single trial to compute it, because the trial dimension will be used as the unit-of-observation for the connectivity estimate.

Best wishes,
Jan-Mathijs

On 9 Aug 2023, at 20:24, Selena Zhang via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> wrote:

Hello all,

I'm new to FieldTrip so I would appreciate any help I can get.
I'm trying to plot the connectivity of many different channels with the direct transfer function.

My problem right now is that once I get the output of ft_freqanalysis, the time scale just runs through all of the trials instead of just the length of one trial. I did ft_definetrial, and it properly defined all 54 trials, although it didn't detect any events, so I'm not sure what the problem could be.

Here is my code:

cfg = [];
cfg.trialfun = 'ft_trialfun_general';
cfg.eventtype = 1;
cfg.trialdfef.eventvalue = 1; % limits to only valid and Go trials (in case of GNG)
cfg.trialdef.prestimulus = min2/fs;
cfg.trialdef.poststimulus = min3/fs;
cfg.dataset = 'Users/selenazhang/Documents/MATLAB/blxlab/data/Data P024 Direct Reach/connectivity/P24DR_rawdata.mat';
cfg.trialdef.ntrials = length(trials);
cfg.trialdef.length = (min2+min3+1)/fs;
[cfg] = ft_definetrial(cfg);

cfg.channel = 'all';
cfg.continuous = 'yes';
[preprocess_data] = ft_preprocessing(cfg, rawdata);

cfg = [];
cfg.method = 'mtmconvol'; % multi taper time-freq analysis
cfg.output = 'powandcsd'; % power and cross spectrum
cfg.channel = 'all';
cfg.trials = 'all';
cfg.pad = 3; % adding padding allows for desired foi
cfg.channelcmb = {'all' 'all'}; % which channels to cross spectrum
cfg.taper = 'hanning';
cfg.foi = 13:1:30; % frequency of interests [13 30] Hz
cfg.t_ftimwin = ones(1,length(cfg.foi))*.4; % moving window in seconds as a 1xnumfoi vector
cfg.toi = '99%'; % overlap of each window, like step size
cfg.avgovertrials = 'yes';
[freqanalysis_data] = ft_freqanalysis(cfg, preprocess_data);


Any idea of what could be wrong? (rawdata is structured the way ft_datatyperaw describes) Thanks!

Best,
Selena
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!7fpApjTY9lQ9-UFzRMOYK_kBRm_dRlAjJl0WV3nKrAYQGFFcXObuDxdPEe6wB8prGyCNIAemmHD3OeScmSzQCFSAGWo_o7NhewiuvA$ 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20230810/18e86426/attachment.htm>


More information about the fieldtrip mailing list