From 2ab4e7bbe2c216119d6c35965a7ea738a19b2428 Mon Sep 17 00:00:00 2001 From: Guy Scharf Date: Thu, 8 Jul 2021 10:28:53 -0700 Subject: [PATCH] Calcs.cpp - calculation of TV and MV now uses a rolling average Only a few loaders are affected by this, notably SleepStyle but not ResMed A rolling average calculation makes calculated values resemble CPAP values more closely --- oscar/SleepLib/calcs.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/oscar/SleepLib/calcs.cpp b/oscar/SleepLib/calcs.cpp index d69a281a..a7f5b196 100644 --- a/oscar/SleepLib/calcs.cpp +++ b/oscar/SleepLib/calcs.cpp @@ -480,6 +480,7 @@ void FlowParser::calc(bool calcResp, bool calcTv, bool calcTi, bool calcTe, bool quint32 *tv_tptr = nullptr; EventStoreType *tv_dptr = nullptr; int tv_count = 0; + double tvlast, tvlast2, tvlast3; if (calcTv) { TV = m_session->AddEventList(CPAP_TidalVolume, EVL_Event); @@ -598,8 +599,15 @@ void FlowParser::calc(bool calcResp, bool calcTv, bool calcTi, bool calcTe, bool //double x=sqrt(q)*2; //val2=x; - if (tv < mintv) { mintv = tv; } + // Average TV over last three data points + if (tv_count == 0) + tvlast = tvlast2 = tvlast3 = tv; + tv = (tvlast + tvlast2 + tvlast3 + tv*2)/5; + tvlast3 = tvlast2; + tvlast2 = tvlast; + tvlast = tv; + if (tv < mintv) { mintv = tv; } if (tv > maxtv) { maxtv = tv; } *tv_tptr++ = timeval; @@ -889,8 +897,9 @@ void calcRespRate(Session *session, FlowParser *flowparser) bool calcTe = !session->eventlist.contains(CPAP_Te); bool calcMv = !session->eventlist.contains(CPAP_MinuteVent); - int z = (calcResp ? 1 : 0) + (calcTv ? 1 : 0) + (calcMv ? 1 : 0); +// Force calculation for testing calculation vs CPAP data +// z = 1; // If any of these three missing, remove all, and switch all on if (z > 0 && z < 3) {