Skip to content

Instantly share code, notes, and snippets.

@pellekrogholt
Last active December 19, 2015 15:08
Show Gist options
  • Save pellekrogholt/5973833 to your computer and use it in GitHub Desktop.
Save pellekrogholt/5973833 to your computer and use it in GitHub Desktop.
%% Simple experiment 2 minutes open eyes then 2 minutes closed eyes
%% in a relaxed position.
%%
%% 2 datasets with 1 epoch for each
%%
%% require eeglab to be loaded:
%% >> cd <path>/eeglab
%% >> eeglab
%%
%% clear study - don't do clear all it also removes eeglab and such:
STUDY = []; CURRENTSTUDY = 0; ALLEEG = []; EEG=[]; CURRENTSET=[];
%% setup
sampling_rate = 512;
epoch_size = 1;
number_of_channels = 1;
load('raw-2013_06_20_14_55_01_mat_binary.mat');
data_length = length(data);
% spilt data in 2 for 2 data sets
if (mod(data_length, 2) == 1)
data_length= data_length-1;
end
data_length_half = data_length/2;
data1 = data(1:data_length_half ,:);
data2 = data(data_length_half+1:data_length ,:);
assert(length(data1)==length(data2));
% note:
% we do transpose because it needs to be a num of channels X
% recordings matrix: 1 x N - and data is N x 1
eegdata_eyes_open = data1';
eegdata_eyes_closed = data2';
assert(length(eegdata_eyes_open)==length(eegdata_eyes_closed));
%% data set 1
data_var_name = 'eegdata_eyes_open';
data_set_name = 'Eyes open';
EEG = pop_importdata( ...
'dataformat','array',...
'nbchan',number_of_channels,...
'data',data_var_name,...
'setname',data_set_name,...
'srate',sampling_rate,...
'pnts',epoch_size,...
'xmin',0);
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG,1,'setname',data_set_name,'gui','off');
eeglab redraw;
%% show channels
%% niecetohave: how to remove dc from script?
EEG = eeg_checkset( EEG );
pop_eegplot( EEG, 1, 1, 1);
%% show spectrogram (pwelch)
figure; pop_spectopo( ...
EEG, ...
1, ...
[(getfield(EEG, 'xmin') * 1000) (getfield(EEG, 'xmax') * 1000)],...
'EEG' , 'freqrange',[2 25],'electrodes','off');
eeglab redraw;
%% data set 2
data_var_name = 'eegdata_eyes_closed';
data_set_name = 'Eyes closed';
EEG = pop_importdata( ...
'dataformat','array',...
'nbchan',number_of_channels,...
'data',data_var_name,...
'setname',data_set_name,...
'srate',sampling_rate,...
'pnts',epoch_size,...
'xmin',0);
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG,2,'setname',data_set_name,'gui','off');
eeglab redraw;
%% show channels
%% niecetohave: how to remove dc from script?
EEG = eeg_checkset( EEG );
pop_eegplot( EEG, 1, 1, 1);
%% plot spectra map and 2-d brain map (last would requires locations
%% set up.)
EEG = eeg_checkset( EEG );
figure; pop_spectopo( ...
EEG, ...
2, ...
[(getfield(EEG, 'xmin') * 1000) (getfield(EEG, 'xmax') * 1000)],...
'EEG' , 'freqrange',[2 25],'electrodes','off');
eeglab redraw;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment