-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchild_rhyme_preproc.m
More file actions
131 lines (86 loc) · 3.5 KB
/
child_rhyme_preproc.m
File metadata and controls
131 lines (86 loc) · 3.5 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
%% Child_Rhyme preprocessing
%{ This is the script for preprocessing eeg data for the child EEG rhyme
%project in the Language, Environment and NeuroDevelopment (LEND) Lab at
%Louisiana State University.
%}
% Author: Will Decker
% Date: January 30, 2024
% Updates:
% 02/01/24: Will Decker finished initial version of script
%% Dirs and locations
% user account
USER = char(getenv('USER'));
if ~strcmp(USER, 'lendlab')
USER = 'lendlab';
end
% directory vars as chars
lendserv = strcat('/Volumes/', USER, '/');
projectdir = strcat(lendserv, 'projects/Child_Rhyme/');
scriptsdir = strcat(projectdir, 'analysis/scripts/EEG-Rhyme-Scripts/');
rawdir = strcat(projectdir, 'data/eeg/');
workdir = strcat(projectdir, 'analysis/workdir');
txtdir = strcat(projectdir, 'analysis/txtdir');
erpdir = strcat(projectdir,'analysis/erpdir');
% dir object
eegdirs = struct(...
'lendserv', {dir(fullfile(lendserv))}, ...
'projectdir', {dir(fullfile(projectdir))}, ...
'scriptsdir', {dir(fullfile(scriptsdir))}, ...
'rawdir', {dir(fullfile(rawdir))},...
'workdir', {dir(fullfile(workdir))}, ...
'txtdir', {dir(fullfile(txtdir))}, ...
'erpdir', {dir(fullfile(erpdir))});
%% Enter necessary dir
cd(char({eegdirs.scriptsdir(1).folder}.'))
%% Establish some constants and variables
% filter and epoch params
lowpass = 30; % in Hz
highpass = 0.1; % in Hz
EPOCH_BASELINE = -500.0; % epoch baseline
EPOCH_END = 1000.0; % epoch offset
% establish subject list
[d,s,r] = xlsread([txtdir '/subjects.xlsx']);
subject_list = r;
numsubjects = (length(s));
%% Start EEGLAB
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
eeglab nogui
%% Filter, reref and remove empty time blocks
% which subjects to run?
sub_start = 1; % start with first subject
sub_end = r{end}; % end with the last subject
% iter through subjects
for s = sub_start:sub_end
subject = subject_list{s};
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
eeglab('redraw');
EEG = pop_loadbv(rawdir, [subject '.vhdr'], [], []);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, 0,'setname',subject,'gui','off');
EEG = eeg_checkset( EEG );
EEG = pop_eegfilt ( EEG, highpass, lowpass, [], [0], 0, 0, 'fir1', 0);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET,'setname',[subject '_fl'],'gui','off');
EEG = eeg_checkset( EEG );
EEG = pop_reref ( EEG, []);
[ALLEEG, EEG, CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET,'setname',[subject '_fl_rr'],'gui','off');
EEG = eeg_checkset( EEG );
EEG = erplab_deleteTimeSegments(EEG, 0, 3000, 3000); %preserves data 3000ms before and after any event code, all other data is removed.
EEG = pop_saveset( EEG, [subject '_fl_rr'], workdir);
end
%% Interpolate bad electrodes
% This step is done manually
%% Idependent Component Analysis (ICA)
% which subjects to run?
sub_start = 1; % start with first subject
sub_end = r{end}; % end with the last subject
for s = sub_start:sub_end
subject = subject_list{s};
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
eeglab('redraw');
EEG = pop_loadset ([subject '_clean.set'],workdir); % ensure that all files are properly named; the code will not work unless the files are named correctly
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
EEG = pop_runica(EEG, 'icatype', 'runica', 'extended',1,'interrupt','on');
[ALLEEG, EEG] = eeg_store(ALLEEG, EEG, CURRENTSET);
EEG = pop_saveset( EEG, [subject '_ICA'], workdir);
end
%% Removing bad ICA Components with MARA
% This step is done manually