Skip to content

Instantly share code, notes, and snippets.

@pellekrogholt
Last active December 19, 2015 15:08
Show Gist options
  • Save pellekrogholt/5973877 to your computer and use it in GitHub Desktop.
Save pellekrogholt/5973877 to your computer and use it in GitHub Desktop.
%% Simple experiment 2 minutes open eyes then 2 minutes closed eyes
%% in a relaxed position.
%%
%% 1 dataset with 2 epochs
%%
%% 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;
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
epoch_size = data_length/2;
% 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_closed = data';
eegdata_eyes_open_closed = eegdata_eyes_open_closed(1, 1:data_length);
assert(length(eegdata_eyes_open_closed)==data_length);
%% data set 1
data_var_name = 'eegdata_eyes_open_closed';
data_set_name = 'Eyes open - 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,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)
EEG = eeg_checkset( EEG );
figure; pop_spectopo( ...
EEG, ...
1, ...
[(getfield(EEG, 'xmin') * 1000) (getfield(EEG, 'xmax') * 1000)],...
'EEG' , 'freqrange',[2 25],'electrodes','off');
eeglab redraw;
%%
%% Possible (fir) filter that data before spectrogram
%% - what else?
EEG = pop_eegfiltnew(EEG, 2, 25, 1690, 0, [], 1);
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 1,'setname',['Eyes ' ...
'open - closed - filtered'],'gui','off');
EEG = eeg_checkset( EEG );
figure; pop_spectopo( ...
EEG, ...
1, ...
[(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