Diff of /preprocessing/BCIIV2a.m [000000] .. [8bbec7]

Switch to unified view

a b/preprocessing/BCIIV2a.m
1
% An example to get the BCI competition IV datasets 2a, 2b is the same
2
% Data from: http://www.bbci.de/competition/iv/
3
% using open-source toolbox Biosig on MATLAB: http://biosig.sourceforge.net/
4
% Just an example, you should change as you need.
5
6
function data = getData(subject_index)
7
8
subject_index = 6; % 1-9
9
10
%% T data
11
session_type = 'T'; % T and E
12
dir_1 = ['D:\MI\BCICIV_2a_gdf\A0',num2str(subject_index),session_type,'.gdf']; % set your path of the downloaded data
13
[s, HDR] = sload(dir_1);
14
15
% Label 
16
% label = HDR.Classlabel;
17
labeldir_1 = ['D:\MI\true_labels\A0',num2str(subject_index),session_type,'.mat'];
18
load(labeldir_1);
19
label_1 = classlabel;
20
21
% construct sample - data Section 1000*22*288
22
Pos = HDR.EVENT.POS; % use POS to get trials
23
% Dur = HDR.EVENT.DUR;
24
Typ = HDR.EVENT.TYP;
25
26
k = 0;
27
data_1 = zeros(1000,22,288);
28
for j = 1:length(Typ)
29
    if  Typ(j) == 768
30
        k = k+1;
31
        data_1(:,:,k) = s((Pos(j)+500):(Pos(j)+1499),1:22);
32
    end
33
end
34
35
% wipe off NaN
36
data_1(isnan(data_1)) = 0;
37
38
39
% E data
40
session_type = 'E';
41
dir_2 = ['D:\Lab\MI\BCICIV_2a_gdf\A0',num2str(subject_index),session_type,'.gdf'];
42
% dir = 'D:\Lab\MI\BCICIV_2a_gdf\A01E.gdf';
43
[s, HDR] = sload(dir_2);
44
45
% Label 
46
% label = HDR.Classlabel;
47
labeldir_2 = ['D:\Lab\MI\true_labels\A0',num2str(subject_index),session_type,'.mat'];
48
load(labeldir_2);
49
label_2 = classlabel;
50
51
% construct sample - data Section 1000*22*288
52
Pos = HDR.EVENT.POS;
53
% Dur = HDR.EVENT.DUR;
54
Typ = HDR.EVENT.TYP;
55
56
k = 0;
57
data_2 = zeros(1000,22,288);
58
for j = 1:length(Typ)
59
    if  Typ(j) == 768
60
        k = k+1;
61
        data_2(:,:,k) = s((Pos(j)+500):(Pos(j)+1499),1:22);
62
    end
63
end
64
65
% wipe off NaN
66
data_2(isnan(data_2)) = 0;
67
68
%% preprocessing
69
% option - band-pass filter
70
fc = 250; % sampling rate
71
Wl = 4; Wh = 40; % pass band
72
Wn = [Wl*2 Wh*2]/fc;
73
[b,a]=cheby2(6,60,Wn);
74
for j = 1:288
75
    data_1(:,:,j) = filtfilt(b,a,data_1(:,:,j));
76
    data_2(:,:,j) = filtfilt(b,a,data_2(:,:,j));
77
end
78
79
% option - a simple standardization
80
%{
81
eeg_mean = mean(data,3);
82
eeg_std = std(data,1,3); 
83
fb_data = (data-eeg_mean)./eeg_std;
84
%}
85
86
%% Save the data to a mat file 
87
data = data_1;
88
label = label_1;
89
% label = t_label + 1;
90
saveDir = ['D:\MI\standard_2a_data\A0',num2str(subject_index),'T.mat'];
91
save(saveDir,'data','label');
92
93
data = data_2;
94
label = label_2;
95
saveDir = ['D:\MI\standard_2a_data\A0',num2str(subject_index),'E.mat'];
96
save(saveDir,'data','label');
97
98
end
99
100
101