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
Change these to appropriate paths for your operating system and setup
%% paths
addpath /home/lau/matlab/fieldtrip-20170613_workshop_natmeg/
ft_defaults
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);
Make subject and recording specific paths (the cell array “subjects_and_dates” can be expanded)
%% subjects and dates
subjects_and_dates = ...
{
'NatMEG_0177/170424/'
};
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
We are loading three different files here:
(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;
end
%% 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 = [];
cfg.channel = {'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);
Notice the peaks around 55 msec and 135 msec
Create a grid around the brain and estimate the leadfield for each of the grid points in the brain
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;
cfg.channel = 'megmag';
leadfield_mag = ft_prepare_leadfield(cfg, timelockeds{1});
cfg.channel = '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'));
ft_plot_vol(headmodel_meg);
view([-45 20]) %% try to rotate it yourself with the plot tools