Please read this about paths and files before you proceed!

Note that if work from the path where all the downloadable parts are downloaded to, you don’t need to change the paths
(leave them as is, but do evaluate the sections)
The paths simply serve as an example of how you can set up your analysis structure, which is especially useful if you have more than one subject

Set up general paths

Change these to appropriate paths for your operating system and setup

%% paths

addpath /home/lau/matlab/fieldtrip-20170613_workshop_natmeg/

raw_meg_path = '/archive/20067_workshop_source_reconstruction/MEG/';
meg_path = '/home/share/workshop_source_reconstruction/data/MEG/';
mri_path = '/home/share/workshop_source_reconstruction/data/MRI/';
set(0, 'DefaultAxesFontWeight', 'bold', 'defaultaxesfontsize', 20, 'defaultlinelinewidth', 2);

Set up subject specific paths

Make subject and recording specific paths (the cell array “subjects_and_dates” can be expanded)

%% subjects and dates

subjects_and_dates = ...

output_path = fullfile(meg_path, subjects_and_dates{1});

events = [1 2 4 8 16]; %% right little, right ring, right middle, right index, right thumb

Load relevant files

We are loading three different files here:

  1. We are loading the timelocked data for the MEG and EEG data
  2. We are loading the headmodels for the MEG data
  3. We are loading the headmodels for the EEG data

(For now leave the tissue_based_headmodel on as ‘yes’, later we will play around with it)

%% go to relevant path and load data

tissue_based_headmodel = 'yes';

% cd(output_path) %% comment this in if you want to set the output path
disp 'Loading timelockeds and headmodel'
load timelockeds.mat
load headmodel_meg.mat
load headmodel_eeg.mat
load headmodel_eeg_fourspheres_elec.mat
load headmodel_meg_singlesphere_headshape.mat
disp Done

if ~strcmp(tissue_based_headmodel, 'yes');
    headmodel_eeg = headmodel_eeg_fourspheres_elec;
    headmodel_eeg.type = 'concentricspheres';
    headmodel_meg = headmodel_meg_singlesphere_headshape;

Identify components of interest

%% identify components of interest

close all
figure('units', 'normalized', 'outerposition', [0 0 1 1]);

% multiplot over all magnetometers
cfg = [];
cfg.layout = 'neuromag306mag.lay'; % layour for magnetometers

ft_multiplotER(cfg, timelockeds{4}); %% explore this by yourself

% combine planar gradiometers (makes them interpretable)

cfg = [];

cmb = ft_combineplanar(cfg, timelockeds{4});

% plot channels "over" SI

cfg = []; = {'MEG0412+0413' 'MEG0422+0423' 'MEG0432+0433' 'MEG0442+0443'}; %% channels "over" SI
cfg.layout = 'neuromag306cmb.lay'; %% layout for combined gradiometers

figure('units', 'normalized', 'outerposition', [0 0 1 1]);

ft_singleplotER(cfg, cmb);
xlabel('Time (s)')
ylabel('Root mean squared activity')

% plot topoplot for early activity
cfg = [];
cfg.layout = 'neuromag306cmb.lay';
cfg.xlim = [0.045 0.065]; % s
cfg.comment = 'no';

figure('units', 'normalized', 'outerposition', [0 0 1 1]);

ft_topoplotER(cfg, cmb);

% plot topoplot for later activity

cfg.xlim = [0.115 0.155]; % s
cfg.zlim = [0 6e-12]; % scale so both peaks can be seen

figure('units', 'normalized', 'outerposition', [0 0 1 1]);

ft_topoplotER(cfg, cmb);

The evoked time courses for the “SI” sensors

Notice the peaks around 55 msec and 135 msec

A topographical plot averaging over 45-65 msec over SI

A topographical plot averaging over 115-155 msec over SII

Create a leadfield and grid

Create a grid around the brain and estimate the leadfield for each of the grid points in the brain

The leadfield is an important concept, which may appear confusing at first

  1. For any given source (a grid point inside the brain) it is calculated how each sensor (magnetomer, gradiometer or electrode) sees (how much T, T/m or V would it pick up) a source with unit strength (1 nAm)
  2. One might say that it says: “For a given source, if it is active, how would it be seen by the different sensors”
  3. It is also sometimes called the forward model

We define the leadfields for each of the three kinds of data here (magnetometers, gradiometers and electrodes)

%% make leadfields eeg and meg

cfg = [];
cfg.headmodel = headmodel_eeg;
cfg.elec = timelockeds{1}.elec;
cfg.senstype = 'eeg';
cfg.grid.resolution = 1;
cfg.grid.unit = 'cm';

leadfield_eeg = ft_prepare_leadfield(cfg, timelockeds{1});

cfg.senstype = 'meg';
cfg.grad = timelockeds{1}.grad;
cfg.headmodel = headmodel_meg; = 'megmag';

leadfield_mag = ft_prepare_leadfield(cfg, timelockeds{1}); = 'meggrad';

leadfield_grad = ft_prepare_leadfield(cfg, timelockeds{1});
%% plot grid and headmodel

figure('units', 'normalized', 'outerposition', [0 0 1 1]);
hold on
ft_plot_mesh(ft_convert_units(leadfield_mag, 'mm'));
view([-45 20]) %% try to rotate it yourself with the plot tools

Show brain inside grid