Averaging Trials
For each stimulus type for each person, we want to average all of the trials together.
We now switch from using EEGLAB to using FieldTrip.
Convieniently, there is a function that allows us to easily switch from EEGLAB to FieldTrip, eeglab2fieldtrip. There is also one that helps you go the other way, fieldtrip2eeglab.
H O W T O
Here's how to use some functions to convert your data to the FieldTrip format and average the trials together.
Open your data in EEGLAB and make sure the dataset of interest is the current one. To do this, click Datasets, and then click the dataset you want.
For each stimulus type for each person, we want to average all of the trials together.
We now switch from using EEGLAB to using FieldTrip.
Convieniently, there is a function that allows us to easily switch from EEGLAB to FieldTrip, eeglab2fieldtrip. There is also one that helps you go the other way, fieldtrip2eeglab.
H O W T O
Here's how to use some functions to convert your data to the FieldTrip format and average the trials together.
Open your data in EEGLAB and make sure the dataset of interest is the current one. To do this, click Datasets, and then click the dataset you want.
Then, run the following code, either in a script or in the command window.
Also, make sure you have set the channel locations in EEGLAB.
Example Code:
% EEGlab to Field Trip
data = eeglab2fieldtrip( EEG, 'preprocessing', 'none' );
% Add code to save the layout structure here if needed
% average all trials together
cfg = [];
[timelock] = ft_timelockanalysis(cfg, data);
% save timelock with the filename of the input file
save('yourfilename.mat','timelock')
This code is from the automation4fxn.m. The yellow sections are the ones you need to replace with your own words or numbers.
Example Code:
% Prepare electrode layout
cfg = [];
cfg.elec = data.elec;
cfg.rotate = 90;%
lay = ft_prepare_layout(cfg);
Saving the Layout Structure for FieldTrip
You only need to do this once for each net (the 256 or 65 electrode net). I've already saved the layout for the GSN256 Net as "lay.mat" in the Matlab Folder.
Just after using the eeglab2fieldtrip function, use the ft_prepare_layout function to prepare the layout structure:
Then, find the 'lay' variable in your workspace. Right click lay and select "Save As"
Save it with a descriptive title, such as "lay256" or "lay64." (I previously saved the 256 net's layout as "lay", so you you might see that around the website.)
To use this saved layout, use the following code:
Replace "lay.mat" with the filename you saved the structure with (ex: "lay256.mat"
load lay.mat; % load the saved GSN256 layout structure
cfg.layout = lay; % set the layout to the one that was just loaded