-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnsrdb.m
117 lines (94 loc) · 3.29 KB
/
nsrdb.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
clear all;
%% Extracting 120s nsrdb normal data
datasets = [16265 16272 16273 16420 16483 16539 16786 16795 17052 17453 18177 18184 19088 19093 19140 19830];
% for i = 1:length(datasets)
% s = num2str(datasets(i));
% ecg = importdata(strcat('normalData/',s,'m.mat'));
% extractedECG1 = ecg(1, (128*100):(128*220));
% extractedECG2 = ecg(2, (128*200):(128*320));
% extractedECG1 = extractedECG1/200;
% extractedECG2 = extractedECG2/200;
% save(strcat('normalExtracted/',s,'_1.mat'),'extractedECG1');
% save(strcat('normalExtracted/',s,'_2.mat'),'extractedECG2');
% end
%% Making feature matrix
featureMatrix = zeros(28,7);
for i = 1:14
s = num2str(datasets(i));
ecg = importdata(strcat('normalExtracted/',s,'_1.mat'));
% resample
[P,Q] = rat(250/128);
ecg = resample(ecg,P,Q);
[qrs_amp_raw,qrs_i_raw,delay]=pan_tompkin(ecg,250,0);
r_mean = mean(qrs_amp_raw);
r_std = std(qrs_amp_raw);
featureMatrix(i,1) = r_mean;
featureMatrix(i,2) = r_std;
[R,Q,S,T,P_w] = MTEO_qrst(ecg,250,0);
if size(Q) == size(S) && Q(1,1) < S(1,1)
x = [Q(:,1) S(:,1)];
signedArea = zeros(size(Q(:,1)));
absArea = zeros(size(Q(:,1)));
for k = 1:size(Q(:,1))
absSum = 0;
signedSum = 0;
for j = x(k,1):x(k,2)
if j == 0
continue;
end
signedSum = signedSum + ecg(j);
absSum = absSum + abs(ecg(j));
end
signedArea(k) = signedSum;
absArea(k) = absSum;
end
qrs_mean = mean(signedArea);
qrs_std = std(signedArea);
qrs_abs_mean = mean(absArea);
qrs_abs_std = std(absArea);
featureMatrix(i,3) = qrs_mean;
featureMatrix(i,4) = qrs_std;
featureMatrix(i,5) = qrs_abs_mean;
featureMatrix(i,6) = qrs_abs_std;
featureMatrix(i,7) = 0;
else
continue;
end
ecg = importdata(strcat('normalExtracted/',s,'_2.mat'));
% resample
[P,Q] = rat(250/128);
ecg = resample(ecg,P,Q);
[qrs_amp_raw,qrs_i_raw,delay]=pan_tompkin(ecg,250,0);
r_mean = mean(qrs_amp_raw);
r_std = std(qrs_amp_raw);
featureMatrix(i+14,1) = r_mean;
featureMatrix(i+14,2) = r_std;
[R,Q,S,T,P_w] = MTEO_qrst(ecg,250,0);
if size(Q) == size(S) && Q(1,1) < S(1,1)
x = [Q(:,1) S(:,1)];
signedArea = zeros(size(Q(:,1)));
absArea = zeros(size(Q(:,1)));
for k = 1:size(Q(:,1))
absSum = 0;
signedSum = 0;
for j = x(k,1):x(k,2)
signedSum = signedSum + ecg(j);
absSum = absSum + abs(ecg(j));
end
signedArea(k) = signedSum;
absArea(k) = absSum;
end
qrs_mean = mean(signedArea);
qrs_std = std(signedArea);
qrs_abs_mean = mean(absArea);
qrs_abs_std = std(absArea);
featureMatrix(i+14,3) = qrs_mean;
featureMatrix(i+14,4) = qrs_std;
featureMatrix(i+14,5) = qrs_abs_mean;
featureMatrix(i+14,6) = qrs_abs_std;
featureMatrix(i+14,7) = 0;
else
continue;
end
end
save('resampledFeatureMatrixNSRDB.mat','featureMatrix');