[FieldTrip] Computing ERFs from HCP MEG Motor Task

Julian Keil julian.keil at gmail.com
Tue Jun 3 15:16:34 CEST 2025


Dear Fabio,

some sanity checks I would suggest:
* Are there NANs in the data somewhere (e.g. any(isnan(data(:)))
* Are the time-axes aliges between all trials?
* Are the channel labels the same in all trials?

Any of these things can lead to omitted data, and given enough trials will
lead to empty data.

Hope this helps,

Julian

On Tue, Jun 3, 2025 at 2:26 PM Fabio Strappazzon via fieldtrip <
fieldtrip at science.ru.nl> wrote:

> Dear all,
>
> I'm trying to extract ERFs from HCP MEG minimally preprocessed data
> from the motor task (right hand trials) and before doing the trial
> averaging I'm computing very simple operations (trial selection,
> 0.5-60 Hz bandpass filtering and demeaning).
> I'm considering each run as independent, giving the fact that the
> sensor information is different across the two runs and this might
> affect the future source reconstruction.
> However, when I then compute the trial average, the evoked activity is
> not evident.
> Am I missing something?
>
> This is the script:
>
> clear all
> close all
> clc
>
> filesystem_dir % retrieves directories
> ft_init
> cd(scriptsdir)
> mySub = '177746';
> preprocdir = [datadir,mySub,'\MEG\Motort\tmegpreproc']; % preprocessed
> data dir
> subj_resdir = [resdir,mySub]; % results directory
> irun = 10;
>
> % loads minimally preprocessed data and trialinfo
> cd(preprocdir)
> load(sprintf([mySub,'_MEG_%d-Motort_tmegpreproc_TEMG.mat'],irun)) %
> run 1 (t0 is the EMG onset)
> load(sprintf([mySub,'_MEG_%d-Motort_tmegpreproc_trialinfo.mat'],irun))
> % WARNING: First columns are for EMG onsets, seconds for flash
> stimulus onset
>
> % selecting only right hand data
> cfg = [];
> cfg.channel = {'MEG'}; % read all MEG channels except EMG channels
> cfg.trials = find(data.trialinfo(:, 2) == 4); % select only right hand
> trials
> data_rh = ft_selectdata(cfg, data);
>
> % Wide-band BP filtering (prior to baseline correction):
> cfg = [];
> cfg.hpfilter = 'yes';
> cfg.hpfreq = .5;
> fdata_temp = ft_preprocessing(cfg, data_rh);
>
> cfg = [];
> cfg.lpfilter = 'yes';
> cfg.lpfreq = 60;
> fdata_rh = ft_preprocessing(cfg, fdata_temp);
>
> % Baseline correcting epochs;
> cfg = [];
> cfg.demean = 'yes';
> cfg.baselinewindow = [-0.3 0]; % -300 ms to 0 (chosen by HCP)
> fdata2avg = ft_preprocessing(cfg, fdata_rh);
>
> % ERF (avg across bsln corrected trials)
> cfg = [];
> avg_rh = ft_timelockanalysis(cfg, fdata2avg);
>
> % Plot
> cfg = [];
> cfg.showlabels = 'yes';
> cfg.fontsize = 6;
> cfg.layout = '4d248_helmet.mat';
> cfg.ylim = [-3e-13 3e-13]; % problem is present also when the scale is
> adjusted
> ft_multiplotER(cfg, avg_rh);
>
> Thanks in advance.
> Best regards,
>
> Fabio.
> _______________________________________________
> fieldtrip mailing list
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmailman.science.ru.nl%2Fmailman%2Flistinfo%2Ffieldtrip&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C9c039cc120b64a7279ba08dda2a0e63d%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638845534151075745%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=4Zlymo6WOzImsCcjTVd01%2Fx%2BigSpZq%2FSn4mNe5i%2FH%2FM%3D&reserved=0
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdoi.org%2F10.1371%2Fjournal.pcbi.1002202&data=05%7C02%7Cfieldtrip%40science.ru.nl%7C9c039cc120b64a7279ba08dda2a0e63d%7C084578d9400d4a5aa7c7e76ca47af400%7C1%7C0%7C638845534151107823%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=z4hF2i%2BBXvOyqzp8EuZcZTxJa8OYZUKy7knLfvIPwmQ%3D&reserved=0
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20250603/ba5a02b3/attachment.htm>


More information about the fieldtrip mailing list