-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_EEG_preprocess.m
61 lines (48 loc) · 1.51 KB
/
B_EEG_preprocess.m
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
% This script shows the pipeline for data processing.
% 0. Choose and load files
% 1. EOG artifact regression
% 2. Channel Interpolation
% 3. Filter data
% 4. Re-reference signal
% 5. Identify bad data
% 6. Separate data by trials
%
% author of this script: Flavio Raschella
% last modify: 25/05/2020
% contact: [email protected]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Clean workspace
clear all; close all; clc
%% 0. Choose and load files
path_name = [pwd filesep 'data'];
EEG_files = {'EEG_data_prepared.mat'};
data_num = numel(EEG_files);
EEG = cell(data_num,1);
for fl = 1:data_num
tmp = load([path_name filesep EEG_files{fl}]);
EEG{fl} = tmp;
end
%% 1. EOG artifact regression
EEG = remove_EOG(EEG);
%% 2. Channel Interpolation
% To get Triangulation Weight :
% Cartool merge EEG + xzy > click xyz window > options> Exp triangulation distances
[~,~,~,tri_Mat] = readfile_sef([path_name filesep 'TriangulationWeights.sef']);
EEG = interpolate_channel(EEG,tri_Mat);
%% 3. Filter data
% bandpass (1-200Hz) and notch (50Hz)
EEG = filter_data(EEG,'band',[1, 200]);
EEG = filter_data(EEG,'notch',50);
%% Plot data
% eeglab must be on the path
% pop_eegplot(EEG{1}, 1, 1, 1);
%% 4. Re-reference signal
EEG = CAR(EEG);
%% 5. Identify bad data
EEG = rej_EEG_by_abs_value(EEG);
%% 6. Separate data by trials
EEG_rest = get_trials(EEG, '"rest"');
EEG_trial = get_trials(EEG, '"trial"');
%% 7. Save data
save([path_name filesep 'EEG_data_processed.mat'],'EEG_rest','EEG_trial')
% EOF