-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOSTCLAS.CPP
233 lines (183 loc) · 7.45 KB
/
POSTCLAS.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*****************************************************************************
FILE: postclas.cppAUTHOR: Patrick S. HamiltonREVISED: 5/13/2002 ___________________________________________________________________________postclas.cpp: Post classifierCopywrite (C) 2002 Patrick S. HamiltonThis file is free software; you can redistribute it and/or modify it underthe terms of the GNU Library General Public License as published by the FreeSoftware Foundation; either version 2 of the License, or (at your option) anylater version.This software is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR APARTICULAR PURPOSE. See the GNU Library General Public License for moredetails.You should have received a copy of the GNU Library General Public License alongwith this library; if not, write to the Free Software Foundation, Inc., 59Temple Place - Suite 330, Boston, MA 02111-1307, USA.You may contact the author by e-mail ([email protected]) or postal mail(Patrick Hamilton, E.P. Limited, 35 Medford St., Suite 204 Somerville,MA 02143 USA). For updates to this software, please visit our website(http://www.eplimited.com). __________________________________________________________________________This file contains functions for classifying beats based after thefollowing beat is detected. ResetPostClassify() -- Resets static variables used by PostClassify() PostClassify() -- classifies each beat based on six preceding beats and the following beat. CheckPostClass() -- classifys beat type based on the last eight post classifications of that beat. CheckPCRhythm() -- returns the classification of the RR interval for this type of beat based its previous eight RR intervals.****************************************************************/
#include "bdac.h"
#include "ecgcodes.h"
// External Prototypes.
double DomCompare(int newType, int domType) ;
int GetBeatTypeCount(int type) ;
// Records of post classifications.
int PostClass[MAXTYPES][8], PCInitCount = 0 ;
int PCRhythm[MAXTYPES][8] ;
/**********************************************************************
Resets post classifications for beats.
**********************************************************************/
void ResetPostClassify()
{
int i, j ;
for(i = 0; i < MAXTYPES; ++i)
for(j = 0; j < 8; ++j)
{
PostClass[i][j] = 0 ;
PCRhythm[i][j] = 0 ;
}
PCInitCount = 0 ;
}
/***********************************************************************
Classify the previous beat type and rhythm type based on this beat
and the preceding beat. This classifier is more sensitive
to detecting premature beats followed by compensitory pauses.
************************************************************************/
void PostClassify(int *recentTypes, int domType, int *recentRRs, int width, double mi2,
int rhythmClass)
{
static int lastRC, lastWidth ;
static double lastMI2 ;
int i, regCount, pvcCount, normRR ;
double mi3 ;
// If the preceeding and following beats are the same type,
// they are generally regular, and reasonably close in shape
// to the dominant type, consider them to be dominant.
if((recentTypes[0] == recentTypes[2]) && (recentTypes[0] != domType)
&& (recentTypes[0] != recentTypes[1]))
{
mi3 = DomCompare(recentTypes[0],domType) ;
for(i = regCount = 0; i < 8; ++i)
if(PCRhythm[recentTypes[0]][i] == NORMAL)
++regCount ;
if((mi3 < 2.0) && (regCount > 6))
domType = recentTypes[0] ;
}
// Don't do anything until four beats have gone by.
if(PCInitCount < 3)
{
++PCInitCount ;
lastWidth = width ;
lastMI2 = 0 ;
lastRC = 0 ;
return ;
}
if(recentTypes[1] < MAXTYPES)
{
// Find first NN interval.
for(i = 2; (i < 7) && (recentTypes[i] != recentTypes[i+1]); ++i) ;
if(i == 7) normRR = 0 ;
else normRR = recentRRs[i] ;
// Shift the previous beat classifications to make room for the
// new classification.
for(i = pvcCount = 0; i < 8; ++i)
if(PostClass[recentTypes[1]][i] == PVC)
++pvcCount ;
for(i = 7; i > 0; --i)
{
PostClass[recentTypes[1]][i] = PostClass[recentTypes[1]][i-1] ;
PCRhythm[recentTypes[1]][i] = PCRhythm[recentTypes[1]][i-1] ;
}
// If the beat is premature followed by a compensitory pause and the
// previous and following beats are normal, post classify as
// a PVC.
if(((normRR-(normRR>>3)) >= recentRRs[1]) && ((recentRRs[0]-(recentRRs[0]>>3)) >= normRR)// && (lastMI2 > 3)
&& (recentTypes[0] == domType) && (recentTypes[2] == domType)
&& (recentTypes[1] != domType))
PostClass[recentTypes[1]][0] = PVC ;
// If previous two were classified as PVCs, and this is at least slightly
// premature, classify as a PVC.
else if(((normRR-(normRR>>4)) > recentRRs[1]) && ((normRR+(normRR>>4)) < recentRRs[0]) &&
(((PostClass[recentTypes[1]][1] == PVC) && (PostClass[recentTypes[1]][2] == PVC)) ||
(pvcCount >= 6) ) &&
(recentTypes[0] == domType) && (recentTypes[2] == domType) && (recentTypes[1] != domType))
PostClass[recentTypes[1]][0] = PVC ;
// If the previous and following beats are the dominant beat type,
// and this beat is significantly different from the dominant,
// call it a PVC.
else if((recentTypes[0] == domType) && (recentTypes[2] == domType) && (lastMI2 > 2.5))
PostClass[recentTypes[1]][0] = PVC ;
// Otherwise post classify this beat as UNKNOWN.
else PostClass[recentTypes[1]][0] = UNKNOWN ;
// If the beat is premature followed by a compensitory pause, post
// classify the rhythm as PVC.
if(((normRR-(normRR>>3)) > recentRRs[1]) && ((recentRRs[0]-(recentRRs[0]>>3)) > normRR))
PCRhythm[recentTypes[1]][0] = PVC ;
// Otherwise, post classify the rhythm as the same as the
// regular rhythm classification.
else PCRhythm[recentTypes[1]][0] = lastRC ;
}
lastWidth = width ;
lastMI2 = mi2 ;
lastRC = rhythmClass ;
}
/*************************************************************************
CheckPostClass checks to see if three of the last four or six of the
last eight of a given beat type have been post classified as PVC.
*************************************************************************/
int CheckPostClass(int type)
{
int i, pvcs4 = 0, pvcs8 ;
if(type == MAXTYPES)
return(UNKNOWN) ;
for(i = 0; i < 4; ++i)
if(PostClass[type][i] == PVC)
++pvcs4 ;
for(pvcs8=pvcs4; i < 8; ++i)
if(PostClass[type][i] == PVC)
++pvcs8 ;
if((pvcs4 >= 3) || (pvcs8 >= 6))
return(PVC) ;
else return(UNKNOWN) ;
}
/****************************************************************************
Check classification of previous beats' rhythms based on post beat
classification. If 7 of 8 previous beats were classified as NORMAL
(regular) classify the beat type as NORMAL (regular).
Call it a PVC if 2 of the last 8 were regular.
****************************************************************************/
int CheckPCRhythm(int type)
{
int i, normCount, n ;
if(type == MAXTYPES)
return(UNKNOWN) ;
if(GetBeatTypeCount(type) < 9)
n = GetBeatTypeCount(type)-1 ;
else n = 8 ;
for(i = normCount = 0; i < n; ++i)
if(PCRhythm[type][i] == NORMAL)
++normCount;
if(normCount >= 7)
return(NORMAL) ;
if(((normCount == 0) && (n < 4)) ||
((normCount <= 1) && (n >= 4) && (n < 7)) ||
((normCount <= 2) && (n >= 7)))
return(PVC) ;
return(UNKNOWN) ;
}