-
Notifications
You must be signed in to change notification settings - Fork 1
/
DepressionExtract.m
66 lines (66 loc) · 2.63 KB
/
DepressionExtract.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
pos = 'F:/';
newFolder = [pos, 'Data/'];
% Fz F3 C3 Pz P3 P4 Cz C4 F4
channels = [10, 8, 26, 48, 46, 50, 28, 30, 12];
fs = 500;
newType = 'h5';
dataFolders = dir(pos);
channelNum = length(channels);
for i = 1:length(dataFolders)
folder = dataFolders(i).name;
if length(folder)>14 && strcmp(folder(1:11), 'Depression ')
idFile = [pos, folder, '/ID.xlsx'];
%%%%%%% Octave
pkg load io;
pid = xlsread(idFile, 'Sheet1');
nid = xlsread(idFile, 'Sheet2');
dataPath = [pos, folder, '/Data/'];
dataFiles = dir(dataPath);
for j = 1:length(dataFiles)
dataFile = dataFiles(j).name;
if length(dataFile)>6 && strcmp(dataFile(end-3:end), '.mat')
id = str2double(dataFile(1:3));
if isempty(find(nid==id))
newId = ['P', sprintf('%02d', find(pid==id))];
else
newId = ['N', sprintf('%02d', find(nid==id))];
end
rawData = load([dataPath, dataFile]).EEG;
epochs = 0;
for k = 2:length(rawData.event)
m = rawData.event(k).type;
if length(m) < 4
epochs = epochs + 1;
end
end
data = zeros(channelNum, fs, epochs, "single");
stimuli = cell(epochs, 1);
tmp = 'S ';
% hiconf_pos = [202 203 206 207 220 221];
% hiconf_neg = [212 213 216 217 226 227];
% loconf_pos = [204 205 208 209];
% loconf_neg = [210 211 214 215];
epoch = 1;
for k = 2:length(rawData.event)
m = rawData.event(k).type;
if length(m) < 4
begin = rawData.event(k).latency;
data(:, :, epoch) = rawData.data(channels, begin:begin+fs-1);
stimuli{epoch, 1} = [tmp(1:4-length(m)), m];
epoch = epoch + 1;
end
end
newFile = [newFolder, 'Depr', newId, '.', 'Rein', ...
'1', sprintf('.%03d', epochs), 'epochs.', newType];
disp(newFile);
if strcmp(newType, 'h5')
save('-float-hdf5', newFile, 'data', 'stimuli');
end
if strcmp(newType, 'mat')
save(newFile, 'data', 'stimuli');
end
clear('rawData', 'data', 'stimuli');
end
end
end
end