-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathp300_classifiers.m
138 lines (100 loc) · 3.31 KB
/
p300_classifiers.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
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
clc
clear
close all
addpath(genpath(pwd))
%% common setting
new_sampling_rate = 32; % from 2048 to 32 Hz
sub_numbers = [3,4] ;%[1,3,4,6,7,9];
preprocess_flag = 1; % 0 for skipping preprocessing & epoching step
dataset_dir = [pwd,'\dataset'];
%% subsets of electrodes for classification
% https://www.epfl.ch/labs/mmspg/research/page-58317-en-html/bci-2/bci_datasets/
% Fz, Cz, Pz, Oz
channels = [31 32 13 16];
% Fz, Cz, Pz, Oz, P7, P3, P4, P8
% channels = [31 32 13 16 11 12 19 20];
% Fz, Cz, Pz, Oz, P7, P3, P4, P8, O1, O2, C3, C4, FC1, FC2, CP1, CP2
% channels = [31 32 13 16 11 12 19 20 15 17 8 23 5 26 9 22];
% All electrodes
% channels = [1:32];
%% EEG epoching & preprocessing
if preprocess_flag>0
for i= 1:length(sub_numbers)
clc
sub_numbers(i)
clear subjec_path
for j=1:4
load_path = [dataset_dir,'\subject',num2str(sub_numbers(i)),'\session',num2str(j)];
save_path = [dataset_dir,'\subject',num2str(sub_numbers(i)),'\s',num2str(j),'.mat'];
extracttrials_modified(load_path,save_path, new_sampling_rate);
subjec_path{1,j}=save_path;
end
all_subjects_path{i}=subjec_path;
end
end
%% Classifying data
% classifier_type = {'bayes_lda' , 'svm' , 'lasso_glm','deep_cnn'};
classifier_type = {'bayes_lda' };
for i= 1:length(sub_numbers)
clc
sub_numbers(i)
for j=1:4
load_path = [dataset_dir,'\subject',num2str(sub_numbers(i)),'\session',num2str(j)];
save_path = [dataset_dir,'\subject',num2str(sub_numbers(i)),'\s',num2str(j),'.mat'];
subjec_path{1,j}=save_path;
end
all_subjects_path{i}=subjec_path;
for j=1:length(classifier_type)
[acc(i,j).vals] = classifiers_analysis( all_subjects_path{i} , classifier_type{j}, channels);
end
plot(acc(i,1).vals,'b')
pause(0.5)
end
% plot the results
close all
for i= 1:length(sub_numbers)
figure
for j=1:length(classifier_type)
plot(acc(i,j).vals,'linewidth',1.5)
hold on
grid on
end
ylabel('ACC')
xlabel('trail number')
legend(classifier_type,'Location','best')
title(['subject: ',num2str(sub_numbers(i))])
end
%% Classifying data
% classifier_type = {'bayes_lda' , 'svm' , 'lasso_glm','deep_cnn'};
classifier_type = {'bayes_lda' };
channels_cell = {[31 32 13 16],[31 32 13 16 11 12 19 20],[31 32 13 16 11 12 19 20 15 17 8 23 5 26 9 22],1:32};
channels_cell_name = {'4-channel','8-channel','16-channel','32-channel'};
for i= 1:length(sub_numbers)
clc
sub_numbers(i)
for j=1:4
load_path = [dataset_dir,'\subject',num2str(sub_numbers(i)),'\session',num2str(j)];
save_path = [dataset_dir,'\subject',num2str(sub_numbers(i)),'\s',num2str(j),'.mat'];
subjec_path{1,j}=save_path;
end
all_subjects_path{i}=subjec_path;
for j=1:length(channels_cell)
[acc(i,j).vals] = classifiers_analysis( all_subjects_path{i} , classifier_type{1}, channels_cell{j});
end
plot(acc(i,1).vals,'b')
pause(0.5)
end
% plot the results
close all
for i= 1:length(sub_numbers)
figure
for j=1:length(channels_cell)
plot(acc(i,j).vals,'linewidth',1.5)
hold on
grid on
end
ylabel('ACC')
xlabel('trail number')
legend(channels_cell_name,'Location','best')
title(['subject: ',num2str(sub_numbers(i))])
end