Commit 208d8eec authored by Martynka's avatar Martynka
Browse files

Upload New File

parent 45feb876
clear all
clc
system = 0 %0 (1 = MAC, 0 = Windows, 2=thinkpad martyna)
if system == 1
cd('/Volumes/methlab/Neurometric/Antisaccades/code/eeglab14_1_2b/')
load('/Volumes/methlab/eyepredict/labels105.mat')
eeglab;
close
raw = '/Volumes/methlab/ETH_AS/preprocessed2' % path to preprocessed eeg files
etfolder='/Volumes/methlab/methlab/ETH_AS\EYE'; %et files
%WINDOWS
elseif system == 0 % Windows
cd('\\130.60.169.45\methlab\Neurometric\Antisaccades\code\eeglab14_1_2b')
load('\\130.60.169.45\methlab\eyepredict\labels105.mat')
eeglab;
close
raw= '\\130.60.169.45\methlab\ETH_AS\preprocessed2'; % path to preprocessed eeg files
etfolder='\\130.60.169.45\methlab\ETH_AS\EYE'; %only one file per sbj
end
d=dir(raw) %what folders are in there (each folder = one subject)
d(1:2)=[] % get rid of the . and .. folders as well as .DS_Store on mac/ NOT THE CASE ON WINDOWS
done = 0;
%%
all_eeg_chunks = {};
all_amplitude = {};
all_id = {};
all_phase = {};
all_rel_amplitude = {};
for i=154:370%loop over all subjects
if done >= 370
break
end
if d(i).isdir
subjectfolder=dir([d(i).folder filesep d(i).name ]);
deleteindex=[];
for ii=1:length(subjectfolder)
if not(endsWith(subjectfolder(ii).name, '_EEG.mat')) || startsWith(subjectfolder(ii).name,'bip') || startsWith(subjectfolder(ii).name,'red')
deleteindex(end+1)=ii;
end
end
subjectfolder(deleteindex)=[];
names ={};
for kkk=1:length(subjectfolder)
names{kkk,1} = subjectfolder(kkk).name;
end
clear ind_t ind
for kk = 1:length(subjectfolder)
ind(kk) = ~isempty(strfind(names{kk},['AS']));
end
ind_t = find(ind);
if isempty(ind_t)
continue;
end
load ([subjectfolder(ind_t).folder filesep subjectfolder(ind_t).name]) % gets loaded as EEG
load([etfolder filesep d(i).name filesep d(i).name '_AS_EYE.mat']) %define string of the complete path to the matching ET file.
EEG.id = d(i).name;
%
% %% REDUCE TO 105 electrodes
%
% tbl_channels = struct2table(EEG.chanlocs);
% el_excl = {'E48' 'E49' 'E56' 'E63' 'E68' 'E73' 'E81' 'E88' 'E94' 'E99' 'E107' 'E113' 'E119' 'E1' 'E8' 'E14' 'E17' 'E21' 'E25' 'E32' 'E125' 'E126' 'E127' 'E128'}
%
%
% tbl_excl = table(el_excl');
% tbl_excl.Properties.VariableNames = {'labels'};
%
%
% ind_excl = [];
% for j = 1:size(tbl_excl,1)
% ind_excl(end+1,1) = find(strcmp(tbl_excl.labels(j),[tbl_channels.labels]));
% end
% ind_excl';
%
%
% EEG = pop_select(EEG,'nochannel',ind_excl );
%% filtering and rereferencing
% EEG = pop_eegfiltnew(EEG,0.5,[]);% high pass filter 0.5Hz
EEG = pop_reref(EEG,[]); % reref
orig_nbchan = EEG.nbchan;
EEG.data(EEG.nbchan+1:EEG.nbchan+size(EYE,1),:) = EYE;
EEG.nbchan = EEG.nbchan+size(EYE,1);
% EEG = pop_resample(EEG,200)
%here remove electr from ET and save them as a separate structure
save([d(i).folder filesep d(i).name filesep 'eye.mat'], ...
'EYE', '-v7.3');
%saving ET data TBD
EEG.data = EEG.data(1:orig_nbchan,:)
EEG.nbchan = orig_nbchan ;
% EEG_chunk = {};
% for k=1:28
% EEG_tmp = pop_eegfiltnew(EEG, k, k+2);
% EEG_chunk{k} = struct('id', EEG_tmp.id);
% EEG_chunk{k}.hbert = hilbert(EEG_tmp.data);
% %ampl +phase
% end
% all_eeg_chunks{end+1} = EEG_chunk;
done = done + 1;
eeg_total = pop_eegfiltnew(EEG,1, 30);
eeg_total.hilbert = hilbert(eeg_total.data')';
eeg_total.amplitude = abs(eeg_total.hilbert);
clear phase
clear amplitude
clear rel_amplitude
%%%
for frl = 1:2:28 % or 1:2:30
frh = frl+2;
clear eeg_tmp
eeg_tmp = pop_eegfiltnew(eeg_total,frl, frh);
eeg_tmp.hilbert = hilbert(eeg_tmp.data')';
eeg_tmp.amplitude = abs(eeg_tmp.hilbert);
eeg_tmp.phase = angle(eeg_tmp.hilbert); % phase in radian
eeg_tmp.phase = 180+eeg_tmp.phase*360/2/pi; % phase in degrees (for PAC according to Moritz Köster)
eeg_tmp.rel_amplitude = abs(eeg_tmp.hilbert)./eeg_total.amplitude;
amplitude(frl,:,:) = eeg_tmp.amplitude ;
phase(frl,:,:) = eeg_tmp.phase;
rel_amplitude(frl,:,:) = eeg_tmp.rel_amplitude ;
end
save([d(i).folder filesep d(i).name filesep 'data.mat'], ...
'amplitude', 'phase', 'rel_amplitude', '-v7.3');
% all_amplitude{end+1} = amplitude;
% all_phase{end+1} = phase;
% all_rel_amplitude{end+1} = rel_amplitude;
% all_id{end+1} = EEG.id;
%
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment