-
Notifications
You must be signed in to change notification settings - Fork 38
/
TWaveAltDetector.cpp
153 lines (122 loc) · 4.79 KB
/
TWaveAltDetector.cpp
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
#pragma once
#include "TWaveAltDetector.h"
TWaveAltDetector::TWaveAltDetector(void) {
}
TWaveAltDetector::~TWaveAltDetector(void) {
}
void TWaveAltDetector::setParams(ParametersTypes ¶meterTypes){}
//(const ECGWaves &, const ECGSignalChannel &, ECGInfo &, ECGTWave &) = 0;
void TWaveAltDetector::runModule(const ECGWaves &ecgWaves, const ECGSignalChannel &ecgSignal, ECGInfo &ecgInfo, ECGTWave &ecgTWave) {
try{
this->filteredSignal = ecgSignal;
this->wavesData = ecgWaves;
this->tWaveAltData = ecgTWave;
#ifdef USE_MOCKED_SIGNAL
this->filteredSignal = getMockedSignal();
#endif
detectTWaveAlt();
}catch (...) {
#ifdef DEBUG
cout << "modules TWAveAlt failed" << endl;
#endif
}
}
bool TWaveAltDetector::detectTWaveAlt() {
#ifdef DEBUG
cout << "Detecting TWaveAlt start" << endl;
#endif
int signalSize = wavesData.GetT_end()->signal->size;
int sS = wavesData.GetT_end()->signal->size;
int ilosc = 0;
unsigned int A1, A2, A3, A4;
double ECG_A1, ECG_A2, ECG_A3, ECG_A4;
int k0 = 0, k1 = 0, k2 = 0, k3 = 0;
bool *tmp_detect_tab = new bool[signalSize];
#ifdef DEBUG
cout << "Preparing singals to be detected" << endl;
#endif
for (int i = 0; i + 3 < signalSize; i++) {
ilosc++;
A1 = gsl_vector_int_get(wavesData.GetT_end()->signal, i);
A2 = gsl_vector_int_get(wavesData.GetT_end()->signal, i + 1);
A3 = gsl_vector_int_get(wavesData.GetT_end()->signal, i + 2);
A4 = gsl_vector_int_get(wavesData.GetT_end()->signal, i + 3);
unsigned int size_size = filteredSignal->signal->size;
if (A1 > size_size || A2 > size_size || A3 > size_size || A4 > size_size)
{
//TODO: something went wrong - fix
continue;
}
ECG_A1 = gsl_vector_get(filteredSignal->signal, A1);
ECG_A2 = gsl_vector_get(filteredSignal->signal, A2);
ECG_A3 = gsl_vector_get(filteredSignal->signal, A3);
ECG_A4 = gsl_vector_get(filteredSignal->signal, A4);
if (fabs(ECG_A1 - ECG_A3) < fabs(ECG_A1 - ECG_A2)) {
k1++;
if (fabs(ECG_A2 - ECG_A4) < fabs(ECG_A3 - ECG_A4)) {
k2++;
if (fabs(ECG_A2 - ECG_A4) < fabs(ECG_A1 - ECG_A2)) {
k3++;
if (fabs(ECG_A1 - ECG_A3) < fabs(ECG_A3 - ECG_A4)) {
k0++;
tmp_detect_tab[i] = true;
tmp_detect_tab[i+1] = true;
tmp_detect_tab[i+2] = true;
tmp_detect_tab[i+3] = true;
#ifdef DEBUG
cout << "T_WaveAlt detected" << endl;
#endif
// TWaveAlt detected in window
}
}
}
}
}
// setting number of detected peaks/windows
int num_of_det_pic = 0;
for(int i = 0 ; i < signalSize ; i++) {
if(tmp_detect_tab[i] == true) num_of_det_pic++;
}
IntSignal tmp_twa = IntSignal(new WrappedVectorInt);
tmp_twa->signal = gsl_vector_int_alloc(num_of_det_pic);
// creating vector to be shown
int tmp_i = 0;
for(int i = 0 ; i < signalSize ; i++) {
if(tmp_detect_tab[i] == true) {
gsl_vector_int_set(tmp_twa->signal, tmp_i, i);
tmp_i++;
}
}
/*
int position = 0;
for (int i = 0; i + 3 < signalSize; i++) {
ilosc++;
A1 = gsl_vector_int_get(ecg_waves.GetT_end()->signal, i);
A2 = gsl_vector_int_get(ecg_waves.GetT_end()->signal, i + 1);
A3 = gsl_vector_int_get(ecg_waves.GetT_end()->signal, i + 2);
A4 = gsl_vector_int_get(ecg_waves.GetT_end()->signal, i + 3);
ECG_A1 = gsl_vector_get(ecg_signal, A1);
ECG_A2 = gsl_vector_get(ecg_signal, A2);
ECG_A3 = gsl_vector_get(ecg_signal, A3);
ECG_A4 = gsl_vector_get(ecg_signal, A4);
if (fabs(ECG_A1 - ECG_A3) < fabs(ECG_A1 - ECG_A2)) {
if (fabs(ECG_A2 - ECG_A4) < fabs(ECG_A3 - ECG_A4)) {
if (fabs(ECG_A2 - ECG_A4) < fabs(ECG_A1 - ECG_A2)) {
if (fabs(ECG_A1 - ECG_A3) < fabs(ECG_A3 - ECG_A4)) {
gsl_vector_int_set(tmp_twa, position, i);
}
}
}
}
}
*/
// analysis of TWaveAlt
tWaveAltData.numberOfWinDetected = (double) (num_of_det_pic);
tWaveAltData.percentageOfWinDetected = ((double) (num_of_det_pic)) / ((double) (ilosc));
tWaveAltData.setTWaveAlt(tmp_twa);
// checking if whole signal has alternans
if (tWaveAltData.percentageOfWinDetected >= 0.05)
return true;
else
return false;
}