-
Notifications
You must be signed in to change notification settings - Fork 1
/
LONGST_TASKS.m
167 lines (167 loc) · 6.1 KB
/
LONGST_TASKS.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
warning('off','all');
data_path = 'G:\Shin\longst\';
%data_path = 'C:\Nguyen Pham\MY THESIS\database\stchange\';
%data_path = 'C:\Nguyen Pham\MY THESIS\database\euro\';
%data_path = 'C:\Nguyen Pham\MY THESIS\database\ecgid\pt1\';
% ECGID--------------------------------------------------------------------
%leads = ones(1,20) * 2;
% CAD----------------------------------------------------------------------
recordings = [20011 20221 20271 20272 20274 20461 20161 20361];
%recordings = [20274 20461];
%leads = [2 1 2 2 2 1 1 2];
%recordings = [20171 20181 20201 20211 20221 20231 20241 20251 20261 20271 20272 20274 20461 20361];
%recordings = [20011 20021 20031 20041 20051 20061 20071 20081 20091 20101 20111 20121 20131 20141 20151 20171 20181 20191 20201 20211 20221 20231 20241 20251 20261 20271 20272 20274 20461 20161 20361];
%recordings = 20011:20361;
leads = ones(1,length(recordings));
%recordings = [20011];
%leads = [2];
% recordings = [20011 20431 20221 20271 20272 20273 20274 20451 20461 20151 20161];
% SPSS Compatible Data Output
% recordings = [20431 20221 20271 20272 20273 20274 20451 20461 20151];
%-LONG ST------------------------------------------------------------------
% recordings = [20011 20431 20221 20271 20272 20151];
% leads = [2 1 1 2 2 1];
% R2 = 80%, 10s, 1/10 partition
% R2 = 70%, 30s, 1/10 partition -> Calculate STD
% R2 = 84.5%, 10s, 1/10 partition, trapz only -> Calculate STD
analysis = [];
%-ST CHANGES---------------------------------------------------------------
%recordings = [300 302 303 306 317];
%recordings = [302 306 312];
%leads = [1 1 1 1 1];
%-EUROPE-------------------------------------------------------------------
%recordings = [103 112 118 111 121 119 129 139 133 162 161 154];
%recordings = [103 118 111];
%leads = [1 1 1];
%recordings = [103 112 118 111];
%leads = [1 2 1 1 1 2 2 2 2 2 2 2];
% ANN, 92%, 5 features
% k-NN, 96,8%, 2 cai HR, FBAND, ENERGY_RATIO, 50-50
%-PARAMETERS-------------------------------
HR_bin = [];
meanHR_bin = []; % <----- For sliding window only
stdHR_bin = []; % <----- For sliding window only
FFT_bin = [];
LFHF_bin = [];
DFA_bin = [];
Twave_bin = [];
ANN_bin = [];
FBAND_bin = [];
ENTROPY_bin = [];
STDeviation_bin = [];
meanSTDeviation_bin = []; % <----- For sliding window only
stdSTDeviation_bin = []; % <----- For sliding window only
STslope_bin = [];
ENERGY_RATIO_bin = [];
ENTROPY_CUTOFF_bin = [];
%REPORT PARAMETERS-------------------------
RP_STslope_bin = [];
RP_STdev_bin = [];
RP_HR_bin = [];
RP_DFA_bin = [];
RP_ENERGY_RATIO_bin = [];
RP_ENTROPY_CUTOFF_bin = [];
RP_Tinv_bin = [];
RP_ToR_bin = [];
score_bin = [];
failed_records = {};
%-HRV PARAMETERS-----------------------------------------------------------
HRV_std_bin = [];
HRV_minmax_bin = [];
HRV_min_bin = [];
HRV_max_bin = [];
HRV_DFA_bin = [];
% QUALIFYING DETECTION CODDE-----------------------------------------------
accepted = 0;
rejected = 0;
%------------------------------------------
for record = 1:length(recordings)
%for record = 1:20
try
filename = ['s' num2str(recordings(record))];
%filename = num2str(recordings(record));
%filename = ['e0' num2str(recordings(record))];
%filename = ['rec_' num2str(record)];
disp(filename);
full_path = [data_path filename '.hea'];
ECGw = ECGwrapper( 'recording_name', full_path);
%load([data_path filename '_ECG_delineation.mat']);
% READ SIGANL AND ANNOTATION-------------------------
ann = ECGw.ECG_annotations;
hea = ECGw.ECG_header;
sig = ECGw.read_signal(1,floor(hea.nsamp/10));
sig1_raw = sig(:,leads(record));
sig1_raw = sig1_raw(1:end);
% NORMALIZATION CODES--------------------------------
sig1_raw = sig1_raw - mean(sig1_raw);
L = length(sig1_raw);
Ex = 1/L * sum(abs(sig1_raw).^2);
sig1_raw = sig1_raw / Ex;
% BASELINE REMOVE USING Wavelet_decompose------------
[approx, detail] = wavelet_decompose(sig1_raw, 8, 'db4');
sig1 = sig1_raw - approx(:,8);
%sig1 = sig1_raw;
sig_backup = sig1;
% NORMALIZA THE SIGNAL FROM 0 TO 1
sig1 = sig1 + abs(min(sig1));
sig1 = sig1 / max(sig1);
% QRS DETECTION--------------------------------------
%if exist('wqrs_ECGv1','var')
% QRS = wqrs_ECGv1.time;
%elseif exist('wqrs_V4','var')
% QRS = wqrs_V4.time;
%elseif exist('wqrs_V1','var')
% QRS = wqrs_V1.time;
%elseif exist('wqrs_MLII','var')
% QRS = wqrs_MLII.time;
%elseif exist('wqrs_MV2','var')
% QRS = wqrs_MV2.time;
%elseif exist('wqrs_MV1','var')
% QRS = wqrs_MV1.time;
%end;
%QRS = wavedet;
%fields = fieldnames(QRS);
%fieldname = getfield(QRS,fields{leads(record)});
% GENERAL PARAMETERS---------------------------------
fs = hea.freq;
ts = 1/fs;
%beatNum = length(QRS);
%annNum = length(ann.anntyp);
% FFT PARAMETERS-------------------------------------
FFT_beat_step = 30;
FFT_part_of_total_data_used = 10;
envelope_size = 26;
smooth_type = 'loess';
smooth_span = .01;
% ---------------
% Pon: [111614x1 double]
% P: [111614x1 double]
% Poff: [111614x1 double]
% Ptipo: [111614x1 double]
% QRSon: [111614x1 double]
% qrs: [111614x1 double]
% Q: [111614x1 double]
% R: [111614x1 double]
% S: [111614x1 double]
% QRSoff: [111614x1 double]
% Ton: [111614x1 double]
% T: [111614x1 double]
% Tprima: [111614x1 double]
% Toff: [111614x1 double]
% Ttipo: [111614x1 double]
%BEAT_TO_BEAT;
%SLIDING_WINDOW;
%WAVELET;
try
REPORT;
%WAVELET;
catch
disp('An error occured while calibrating this record');
failed_records{end + 1} = filename;
end;
catch
disp(['record ' filename ' not found. Proceed to next one']);
end;
end;
SCATTER_PLOT;
STATS;