/
scalpmap_eeg.m
76 lines (60 loc) · 2.94 KB
/
scalpmap_eeg.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
% This file is for eeg-data r^2 value scalp map
% Most of MATLAB functions are available in BBCI toolbox
% Some minor code modifications might be applied
% For more tutorials, visit BBCI toolbox (https://github.com/bbci/bbci_public)
% specify your eeg data directory (EegMyDataDir) and temporary directory (TemDir)
startup_bbci_toolbox('DataDir',EegMyDataDir,'TmpDir','/tmp/');
BTB.History = 0; % to aviod error for merging cnt
fs = 200 % downsampling rate: 200 Hz
% initial parameter
subdir_list = {'subject1'}
basename_list = {'imagery1','arithmetic1','imagery1','arithmetic2','imagery1','arithmetic3'};
% Specify discriminative frequency band. Use alpha band for example.
band_csp.imag = [8 14]; % alpha-band for motor imagery
% motor imagery
loadDir = fullfile(EegMyDataDir,subdir_list{1});
cd(loadDir);
load cnt; load mrk; load mnt;
cd(WorkingDir);
cnt_temp = cnt; mrk_temp = mrk; % backup
clear cnt mrk;
[cnt.imag, mrk.imag] = proc_appendCnt({cnt_temp{1}, cnt_temp{3}, cnt_temp{5}}, {mrk_temp{1}, mrk_temp{3}, mrk_temp{5}}); % merged motor imagery cnts
[b,a]= butter(3, band_csp.imag/fs*2);
cnt.imag = proc_filt(cnt.imag, b, a);
%-------------------------------------------------------------------------------------------------------------------------------
% mental arithmetic
% Specify discriminative frequency band. Use alpha band for example.
band_csp.ment = [4 14]; % theta- to alpha-band for mental arithmetic
% load data
loadDir = fullfile(EegMyDataDir,subdir_list{1});
cd(loadDir);
load cnt; load mrk; load mnt;
cd(WorkingDir); % Specify working directory in advance
cnt_temp = cnt; mrk_temp = mrk; % backup
clear cnt mrk;
% merge cnts
[cnt.ment, mrk.ment] = proc_appendCnt({cnt_temp{2}, cnt_temp{4}, cnt_temp{6}}, {mrk_temp{2}, mrk_temp{4}, mrk_temp{6}}); % merged mental arithmetic cnts
% band-pass filtering
[b,a]= butter(3, band_csp.ment/fs*2);
cnt.ment = proc_filt(cnt.ment, b, a);
ival_epo = [-10 25]*1000;
ival_scalps = [-8 -5; -3 0; 2 5; 7 10; 12 15; 17 20]*1000;
%-------------------------------------------------------------------------------------------------------------------------------------
% segmentation
% motor imagery
epo.imag = proc_segmentation(cnt.imag, mrk.imag, ival_epo);
epo.className = {'LMI','RMI'};
epo_car.imag = proc_commonAverageReference(epo.imag);
epo_car.imag = proc_envelope(erd_car.imag, 'MovAvgMsec', 500);
epo_car_r.imag = proc_rSquareSigned(erd_car.imag);
fig_set(1)
plot_scalpEvolution(erd_car_r, mnt_grand, ival_scalps, defopt_scalp_r);
%-------------------------------------------------------------------------------------------------------------------------------------
% mental arithmetic
epo.ment = proc_segmentation(cnt.ment, mrk.ment, ival_epo);
epo.className = {'LMI','RMI'};
epo_car.ment = proc_commonAverageReference(epo.ment);
epo_car.ment = proc_envelope(erd_car.ment, 'MovAvgMsec', 500);
epo_car_r.ment = proc_rSquareSigned(erd_car.ment);
fig_set(2)
plot_scalpEvolution(erd_car_r, mnt_grand, ival_scalps, defopt_scalp_r);