forked from hsd1503/ENCASE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess_sub.m
69 lines (61 loc) · 1.79 KB
/
preprocess_sub.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
function preprocess_sub(recordName)
fout1 = fopen('data1/short.csv','w');
fout2 = fopen('data1/long.csv','w');
fout3 = fopen('data1/QRSinfo.csv','w');
pid = recordName;
label = 1;
%label is not used
[tm,ecg,fs,siginfo]=rdmat(recordName);
[QRS,sign,en_thres] = qrs_detect2(ecg',0.25,0.6,fs);
QRS_info = diff([0 QRS length(ecg)]);
n_iter = 10;
ratio = 0.68;
THRES = 0.6;
iter = 0;
while max(QRS_info) > fs*2
iter = iter + 1;
if iter >= n_iter
break
end
THRES = ratio * THRES;
[QRS,sign,en_thres] = qrs_detect2(ecg',0.25,THRES,fs);
QRS_info = diff([0 QRS length(ecg)]);
end
if max(QRS_info) > length(ecg)*0.9
[QRS,sign,en_thres] = qrs_detect2(ecg'*2,0.25,0.6,fs);
QRS_info = diff([0 QRS length(ecg)]);
end
%%% long数据在ecg中
tmp_len = length(ecg);
fprintf(fout2, '%s,', pid);
fprintf(fout2, '%s,', label);
fprintf(fout2, '%f,',ecg(1:tmp_len-1));
fprintf(fout2, '%f\n',ecg(tmp_len));
%%% short数据在segment中
for i = 1:(length(QRS)-1)
segment = ecg(QRS(i)+1:QRS(i+1));
tmp_len = length(segment);
fprintf(fout1, '%s,', pid);
fprintf(fout1, '%s,', label);
fprintf(fout1, '%f,',segment(1:tmp_len-1));
fprintf(fout1, '%f\n',segment(tmp_len));
end
%%% write qrs info
% add 0 and length to head and tail, diff to get length of each
% segment, notice that the first and the last is not accurate
tmp_len = length(QRS_info);
fprintf(fout3, '%s,', pid);
fprintf(fout3, '%s,', label);
if tmp_len < 2
fprintf(fout3, '%f\n',QRS_info(tmp_len));
else
fprintf(fout3, '%f,',QRS_info(1:tmp_len-1));
fprintf(fout3, '%f\n',QRS_info(tmp_len));
end
%向answers.txt写文件名
fout4 = fopen('answers.txt','a');
fprintf(fout4, '%s,', recordName);
fclose(fout4);
fclose(fout1);
fclose(fout2);
fclose(fout3);