-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript_TM_full.m
More file actions
102 lines (82 loc) · 5.51 KB
/
Script_TM_full.m
File metadata and controls
102 lines (82 loc) · 5.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
% EEGLAB history file generated on the 19-Apr-2019
% change PP no.x to current participant no.
% change no. + group name based on current no. & group
%% Set up data for tonal musicians
subject_list = {'PP4','PP10','PP11','PP12','PP18','PP27','PP31','PP36',...
'PP37','PP41','PP42','PP47','PP50','PP59','PP62'};
numsubjects = length(subject_list); % number of subjects
parentfolder = 'C:\Users\Annette\Desktop\Data\Annette\TonalMusician\';
%% ------------------------------------------------
for s=1:numsubjects
subject = subject_list{s};
subjectfolder = [parentfolder subject '.bdf'];
fprintf('\n\n\n*** Processing subject %d (%s) ***\n\n\n', s, subject);
[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;
EEG = pop_biosig(subjectfolder, 'channels',[1:34] );
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 0,'setname',subject,'gui','off');
% downsample to 512Hz
EEG = eeg_checkset( EEG );
EEG = pop_resample( EEG, 512);
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 1,'savenew',['C:\\Users\\Annette\\Desktop\\Dataset\\New\\' subject '_res.set'],'overwrite','on','gui','off');
% look up channel locations
EEG=pop_chanedit(EEG, 'lookup',...
'C:\\toolbox\\eeglab14_1_2b\\plugins\\dipfit2.3\\standard_BESA\\standard-10-5-cap385.elp');
[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
% filter
EEG = eeg_checkset( EEG );
EEG = pop_eegfiltnew(EEG, [],50,136,0,[],0);
EEG = eeg_checkset( EEG );
EEG = pop_eegfiltnew(EEG, [],0.5,3380,1,[],0);
EEG = eeg_checkset( EEG );
EEG = pop_eegfiltnew(EEG, [],30,226,0,[],0);
% automatic channel rejection ( and save current dataset )
EEG = eeg_checkset( EEG );
EEG = pop_rejchan(EEG, 'elec',[1:32] ,'threshold',5,'norm','on','measure','kurt');
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 1,'setname',[subject ' resampled auto rej'],'saveold',['C:\\Users\\Annette\\Desktop\\Dataset\\New\\' subject '_filt.set'],'gui','off');
% [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'savenew',['C:\\Users\\Annette\\Desktop\\Dataset\\New\\' subject '_cha.set'],'saveold',['C:\\Users\\Annette\\Desktop\\Dataset\\' subject '_res.set'],'gui','off');
% [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'setname', subject,'saveold',['C:\\Users\\Annette\\Desktop\\Dataset\\New\\' subject '_res.set'], 'overwrite','off','gui','off');
% [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'overwrite', 'on', 'gui','off');
% interpolate based on loaded set
EEG = eeg_checkset( EEG );
EEG = pop_interp(EEG, ALLEEG(1).chanlocs, 'spherical');
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'overwrite','on','gui','off');
% eeglab redraw
% rereference to average
EEG = eeg_checkset( EEG );
EEG = pop_reref( EEG, [],'exclude',[33 34] );
% % low pass filter 20 Hz
% EEG = eeg_checkset( EEG );
% EEG = pop_eegfiltnew(EEG, [],20,338,0,[],0);
% [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 3,'setname','PP13 refiltered','saveold','C:\\Users\\Annette\\Desktop\\Dataset\\New\\PP13NM_reref.set','gui','off');
% create eventlist
EEG = pop_creabasiceventlist( EEG , 'AlphanumericCleaning', 'on', 'BoundaryNumeric', { -99 }, 'BoundaryString', { 'boundary' } ); % GUI: 19-Apr-2019 20:47:05
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'gui','off');
% assign bins
EEG = pop_binlister( EEG , 'BDF', 'C:\Users\Annette\Desktop\Dataset\binlister.txt', 'IndexEL', 1, 'SendEL2', 'EEG', 'UpdateEEG', 'on', 'Voutput', 'EEG' ); % GUI: 19-Apr-2019 20:47:27
[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
% save epoched dataset
EEG = pop_epochbin( EEG , [-300.0 2000.0], 'pre'); % GUI: 19-Apr-2019 20:49:00
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'overwrite','on','gui','off');
EEG = pop_saveset( EEG, 'filename',[subject '_epoch.set'],'filepath','C:\\Users\\Annette\\Desktop\\Dataset\\New');
[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
% update GUI
% eeglab redraw;
%% moving window artifact detection (CHANGE CHANNEL NUMBERS / voltage 100 or 75)
EEG = pop_artmwppth( EEG , 'Channel', 1:34, 'Flag', 1, 'Threshold', 100, 'Twindow', [ -300.8 1998], 'Windowsize', 200, 'Windowstep', 100 ); % GUI: 19-Apr-2019 20:50:06
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 2,'gui','off');
EEG = eeg_checkset( EEG );
%% steplike artifact detection (CHANGE CHANNEL NUMBERS / voltage 100 or 75)
EEG = pop_artstep( EEG , 'Channel', 1:34, 'Flag', 1, 'Threshold', 100, 'Twindow', [ -300.8 1998], 'Windowsize', 200, 'Windowstep', 50 ); % GUI: 19-Apr-2019 20:56:33
[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, 3,'savenew',['C:\\Users\\Annette\\Desktop\\Dataset\\New\\' subject '_flagged.set'],'gui','off');
%% save flagged ERP set
EEG = pop_saveset( EEG, 'filename',[subject '_flagged.set'],'filepath','C:\\Users\\Annette\\Desktop\\Dataset\\New');
ERP = pop_averager( ALLEEG , 'Criterion', 'good', 'DSindex', 4, 'ExcludeBoundary', 'on', 'SEM', 'on' );
ERP = pop_savemyerp(ERP, 'erpname', subject, 'filename', [subject '.erp'], 'filepath', ...
'C:\Users\Annette\Desktop\Dataset\TM_New', 'Warning', 'on');
[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
% save artifact rejection summary
EEG = pop_summary_AR_eeg_detection(EEG, ['C:\Users\Annette\Desktop\Dataset\TM_New\AR_summary_' subject '.txt']);
% update GUI
% % eeglab redraw;
end
eeglab redraw