-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathQRSMorphologyDetector.cpp
131 lines (97 loc) · 3.13 KB
/
QRSMorphologyDetector.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
#include "QRSMorphologyDetector.h"
#include <QDebug>
double dlugosc(ECGSignalChannel * signal, int forBegin, int forEnd){
ECGSignalChannel sig;
sig = *signal;
double result = 0;
double tmp1 = gsl_vector_get(sig->signal,forBegin);
double tmp2;
for(int i=forBegin+1;i<forEnd;i++){
tmp2 = tmp1;
tmp1 = gsl_vector_get(sig->signal,i);
result += sqrt(1 + (tmp1-tmp2)*(tmp1-tmp2));
}
return result;
}
double pole(ECGSignalChannel * signal, int forBegin, int forEnd){
ECGSignalChannel sig;
sig = *signal;
double result = 0;
double temp;
for(int i=forBegin;i<forEnd;i++){
temp = gsl_vector_get(sig->signal,i);
if (temp > 0 ) result += temp;
else result -= temp;
}
return result;
}
double stosunek(ECGSignalChannel * signal, int forBegin, int forEnd)
{
ECGSignalChannel sig;
sig = *signal;
double tmp1 = 0;
double tmp2 = 0;
for(int i=forBegin;i<forEnd;i++){
if(gsl_vector_get(sig->signal,i)>0) tmp1 += gsl_vector_get(sig->signal,i);
else tmp2 -= gsl_vector_get(sig->signal,i);
}
if (tmp2 == 0) return 0;
return tmp1/tmp2;
}
double szybkosc(ECGSignalChannel * signal, int forBegin, int forEnd)
{
ECGSignalChannel sig;
sig = *signal;
double tmp1 = 0;
double tmp2;
for(int i=forBegin;i<forEnd-5;i++){
tmp2 = gsl_vector_get(sig->signal,i+5) - gsl_vector_get(sig->signal,i);
if (tmp2<0) tmp2 = -tmp2;
if(tmp2>tmp1) tmp1 = tmp2;
}
return tmp1;
}
QRSMorphologyDetector::QRSMorphologyDetector(void)
{
}
QRSMorphologyDetector::~QRSMorphologyDetector(void)
{
}
void QRSMorphologyDetector::setParams(ParametersTypes ¶meterTypes)
{
}
void QRSMorphologyDetector::runModule(const ECGWaves & waves, const ECGSignalChannel & filteredSignal, const ECGInfo & ecgi, QRSClass & qrsClass)
{
double inputValue = gsl_vector_get (filteredSignal->signal,1);
this->filteredSignal = filteredSignal;
this->qrsPosition = waves;
this->qrsMorphology = &qrsClass;
gsl_vector_int *v = qrsPosition.GetQRS_onset()->signal;
int size = int(v->size);
this->qrsMorphology->setSize(size);
detectQRSMorphology();
}
bool QRSMorphologyDetector::detectQRSMorphology()
{
auto signalSize = filteredSignal->signal->size;
gsl_vector_int *QRS_onset = qrsPosition.GetQRS_onset()->signal;
gsl_vector_int *QRS_end = qrsPosition.GetQRS_end()->signal;
int size = int(QRS_onset->size);
IntSignal tmpSig;
tmpSig = IntSignal(new WrappedVectorInt);
tmpSig->signal = gsl_vector_int_alloc(size);
for(int i=0;i<size;i++){
int start = gsl_vector_int_get(QRS_onset,i);
int stop = gsl_vector_int_get(QRS_end,i);
double poleV = pole(&filteredSignal,start,stop);
double dlugoscV = dlugosc(&filteredSignal,start,stop);
double rm = (dlugoscV/2*sqrt(3.14*poleV))-1;
double stosunekV = stosunek(&filteredSignal,start,stop);
double szybkoscV = szybkosc(&filteredSignal,start,stop);
//dokonczyc ocene rodzaju pobudzenia
if (rm>65 && rm<80 && szybkoscV>0.075) gsl_vector_int_set(tmpSig->signal,i,SUPRACENTRICULAR);
else gsl_vector_int_set(tmpSig->signal,i,VENTRICULUS);
}
qrsMorphology->setQrsMorphology(tmpSig);
return 1;
}