Improved SpO2 Drop Detection algorithm

This commit is contained in:
Mark Watkins 2011-12-11 02:15:47 +10:00
parent f8a134c26f
commit 64a0803806

View File

@ -508,31 +508,43 @@ int calcSPO2Drop(Session *session)
EventDataType lv=0; EventDataType lv=0;
int li=0; int li=0;
// Fix me.. Time scale varies.
const unsigned ringsize=10; const unsigned ringsize=10;
EventDataType ring[ringsize]; EventDataType ring[ringsize]={0};
qint64 rtime[ringsize]={0};
int rp=0; int rp=0;
int min; int min;
int cnt=0;
for (int e=0;e<it.value().size();e++) { for (int e=0;e<it.value().size();e++) {
EventList & el=*(it.value()[e]); EventList & el=*(it.value()[e]);
for (unsigned i=0;i<el.count();i++) { for (unsigned i=0;i<el.count();i++) {
val=el.data(i); val=el.data(i);
if (!val) continue; if (!val) continue;
ring[rp]=val; ring[rp]=val;
time=el.time(i);
rtime[rp]=time;
rp++; rp++;
rp=rp % ringsize; rp=rp % ringsize;
if (i<ringsize) { if (i<ringsize) {
for (unsigned j=i;j<ringsize;j++) { for (unsigned j=i;j<ringsize;j++) {
ring[j]=val; ring[j]=val;
rtime[j]=0;
} }
} }
tmp=0; tmp=0;
cnt=0;
for (unsigned j=0;j<ringsize;j++) { for (unsigned j=0;j<ringsize;j++) {
tmp+=ring[j]; if (rtime[j] > time-window) {
tmp+=ring[j];
cnt++;
}
} }
tmp/=EventDataType(ringsize); if (!cnt) {
unsigned j=abs((rp-1) % ringsize);
tmp=ring[j];
} else tmp/=EventDataType(cnt);
val=tmp; val=tmp;
time=el.time(i);
lastt=0; lastt=0;
lv=val; lv=val;