-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmCon_make_erp.m
More file actions
171 lines (138 loc) · 6.91 KB
/
EmCon_make_erp.m
File metadata and controls
171 lines (138 loc) · 6.91 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
%Create an ERPset from a postart EEGset for EmCon
%
%If an EEGset is currently loaded, this script will create ERPs from the
%current EEGset.
%If no EEGset is loaded, it will ask for a subject ID, load the
%postart EEGset, and creates ERPs from this set.
%
%Author: Eric Fields
%Version Date: 10 August 2023
%Copyright (c) 2023, Eric Fields
%All rights reserved.
%This code is free and open source software made available under the terms
%of the 3-clause BSD license:
%https://opensource.org/licenses/BSD-3-Clause
%% Paremeters and Set-up
%Half-amplitude cutoff of filter for viewing ERP data
lp_cutoff = 20;
%Get main data directory
if ~exist('main_dir', 'var')
main_dir = EmCon_main_dir();
end
%If batch_proc variable is not set, we aren't batch processing
if ~exist('batch_proc', 'var')
batch_proc = false;
end
%% Import EEG data (if necessary)
%Get subject ID
if ~exist('EEG', 'var') && ~batch_proc
%Get subject ID
sub_id = input('\nSubject ID: ', 's');
%start EEGLAB
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab; %#ok<ASGLU>
%Load post-artifact rejection dataset
EEG = pop_loadset('filename', [sub_id '_postart.set'], 'filepath', fullfile(main_dir, 'EEGsets'));
[ALLEEG, EEG, CURRENTSET] = eeg_store(ALLEEG, EEG, 0);
end
%% Make ERP
%Create ERP
ERP = pop_averager(ALLEEG, 'Criterion', 'good', ...
'DQ_custom_wins', 0, 'DQ_flag', 1, 'DQ_preavg_txt', 0, ...
'DSindex', CURRENTSET, 'ExcludeBoundary', 'on', 'SEM', 'on');
if isempty(ALLERP)
ALLERP = ERP;
CURRENTERP = 1;
else
CURRENTERP = CURRENTERP + 1;
ALLERP(CURRENTERP) = ERP;
end
%Add bins
%[ALLERP, ERP, CURRENTERP] = EmCon_add_bins(ALLERP, ERP, CURRENTERP);
%Save ERP
if batch_proc
erp_overwrite_warn = 'off'; %#ok<UNRCH>
else
erp_overwrite_warn = 'on';
end
ERP = pop_savemyerp(ERP, 'erpname', sub_id, 'filename', [sub_id '.erp'], ...
'filepath', fullfile(main_dir, 'ERPsets'), 'Warning', erp_overwrite_warn);
ALLERP(CURRENTERP) = ERP;
%% Create filtered set for viewing
if ~batch_proc
orig_chans = find(~strcmp({ERP.chanlocs.labels}, 'blink'));
ERP = pop_filterp(ERP, orig_chans, 'Cutoff', lp_cutoff, 'Design', 'butter', 'Filter', 'lowpass', 'Order', 2);
ERP.erpname = sprintf('%s_%dHzLP', ERP.erpname, lp_cutoff);
ERP.filename = ''; ERP.filepath = '';
CURRENTERP = CURRENTERP + 1;
ALLERP(CURRENTERP) = ERP;
end
%% Plot for quality check
if ~batch_proc
bin_sets = {[5, 6]};
for b = 1:length(bin_sets)
bins = bin_sets{b};
ERP = pop_ploterps(ERP, [1, 2], orig_chans, ...
'AutoYlim', 'on', ...
'Axsize', [0.05, 0.08], ...
'BinNum', 'on', ...
'Blc', 'no', ...
'Box', [6, 5], ...
'ChLabel', 'on', ...
'FontSizeChan', 10, ...
'FontSizeLeg', 12, ...
'FontSizeTicks', 10, ...
'LegPos', 'bottom', ...
'Linespec', {'k-', 'r-'}, ...
'LineWidth', 1, ...
'Maximize', 'on', ...
'Style', 'Classic', ...
'Tag', 'ERP_figure', ...
'Transparency', 0, ...
'xscale', [-200.0, 800.0, -200:200:800], ...
'YDir', 'reverse' );
end
clear plotset; %Prevents error when trying to use the GUI for additional plotting
eeglab redraw;
erplab redraw;
end
function [ALLERP, ERP, CURRENTERP] = EmCon_add_bins(ALLERP, ERP, CURRENTERP)
%Add difference waves
ERP = pop_binoperator(ERP, {'b72 = b6 - b5 label diff_NEG-NEU_immediate_corr', ...
'b73 = b7 - b5 label diff_animal-NEU_immediate_corr', ...
'b74 = b41 - b40 label diff_Old-New_NEU_immediate_corr', ...
'b75 = b42 - b40 label diff_Know-New_NEU_immediate_corr', ...
'b76 = b43 - b40 label diff_Rem-New_NEU_immediate_corr', ...
'b77 = b43 - b42 label diff_Rem-Know_NEU_immediate_corr', ...
'b78 = b45 - b44 label diff_Old-New_NEG_immediate_corr', ...
'b79 = b46 - b44 label diff_Know-New_NEG_immediate_corr', ...
'b80 = b47 - b44 label diff_Rem-New_NEG_immediate_corr', ...
'b81 = b47 - b46 label diff_Rem-Know_NEG_immediate_corr', ...
'b82 = b49 - b48 label diff_Old-New_animal_immediate_corr', ...
'b83 = b50 - b48 label diff_Know-New_animal_immediate_corr', ...
'b84 = b51 - b48 label diff_Rem-New_animal_immediate_corr', ...
'b85 = b51 - b50 label diff_Rem-Know_animal_immediate_corr', ...
'b86 = b53 - b52 label diff_Old-New_both_immediate_corr', ...
'b87 = b54 - b52 label diff_Know-New_both_immediate_corr', ...
'b88 = b55 - b52 label diff_Rem-New_both_immediate_corr', ...
'b89 = b55 - b54 label diff_Rem-Know_both_immediate_corr', ...
'b90 = b57 - b56 label diff_Old-New_NEU_delayed_corr', ...
'b91 = b58 - b56 label diff_Know-New_NEU_delayed_corr', ...
'b92 = b59 - b56 label diff_Rem-New_NEU_delayed_corr', ...
'b93 = b59 - b58 label diff_Rem-Know_NEU_delayed_corr', ...
'b94 = b61 - b60 label diff_Old-New_NEG_delayed_corr', ...
'b95 = b62 - b60 label diff_Know-New_NEG_delayed_corr', ...
'b96 = b63 - b60 label diff_Rem-New_NEG_delayed_corr', ...
'b97 = b63 - b62 label diff_Rem-Know_NEG_delayed_corr', ...
'b98 = b65 - b64 label diff_Old-New_animal_delayed_corr', ...
'b99 = b66 - b64 label diff_Know-New_animal_delayed_corr', ...
'b100 = b67 - b64 label diff_Rem-New_animal_delayed_corr', ...
'b101 = b67 - b66 label diff_Rem-Know_animal_delayed_corr', ...
'b102 = b69 - b68 label diff_Old-New_both_delayed_corr', ...
'b103 = b70 - b68 label diff_Know-New_both_delayed_corr', ...
'b104 = b71 - b68 label diff_Rem-New_both_delayed_corr', ...
'b105 = b71 - b70 label diff_Rem-Know_both_delayed_corr'});
%Add main effect waves
%TO DO
%Update ALLERP
ALLERP(CURRENTERP) = ERP;
end