diff --git a/Library/include/pulseprocessor.h b/Library/include/pulseprocessor.h index 8109cdd..42c645a 100644 --- a/Library/include/pulseprocessor.h +++ b/Library/include/pulseprocessor.h @@ -68,12 +68,13 @@ class PulseProcessor */ virtual ~PulseProcessor(); /** - * Update ppg signal by one count + * Update vpg signal by one count * @param value - count value * @param time - count measurement time in millisecond + * @param filter - apply filtering of the input values * @note function should be called at each video frame */ - void update(double value, double time); + void update(double value, double time, bool filter=true); /** * Compute heart rate * @return heart rate in beats per minute diff --git a/Library/src/pulseprocessor.cpp b/Library/src/pulseprocessor.cpp index 9cbf113..46e749a 100644 --- a/Library/src/pulseprocessor.cpp +++ b/Library/src/pulseprocessor.cpp @@ -77,41 +77,44 @@ PulseProcessor::~PulseProcessor() delete[] v_FA; } -void PulseProcessor::update(double value, double time) +void PulseProcessor::update(double value, double time, bool filter) { - v_raw[curpos] = value; - if(std::abs(time - m_dTms) < m_dTms) { - v_time[curpos] = time; - } else { - v_time[curpos] = m_dTms; - } + if(filter) { + v_raw[curpos] = value; + if(std::abs(time - m_dTms) < m_dTms) { + v_time[curpos] = time; + } else { + v_time[curpos] = m_dTms; + } - double mean = 0.0; - double sko = 0.0; + double mean = 0.0; + double sko = 0.0; - for(int i = 0; i < m_interval; i++) { - mean += v_raw[__loop(curpos - i)]; - } - mean /= m_interval; - int pos = 0; - for(int i = 0; i < m_interval; i++) { - pos = __loop(curpos - i); - sko += (v_raw[pos] - mean)*(v_raw[pos] - mean); - } - sko = std::sqrt( sko/(m_interval - 1)); - if(sko < 0.01) { - sko = 1.0; - } - v_X[__seek(curpos)] = (v_raw[curpos] - mean)/ sko; + for(int i = 0; i < m_interval; i++) { + mean += v_raw[__loop(curpos - i)]; + } + mean /= m_interval; + int pos = 0; + for(int i = 0; i < m_interval; i++) { + pos = __loop(curpos - i); + sko += (v_raw[pos] - mean)*(v_raw[pos] - mean); + } + sko = std::sqrt( sko/(m_interval - 1)); + if(sko < 0.01) { + sko = 1.0; + } + v_X[__seek(curpos)] = (v_raw[curpos] - mean)/ sko; - double integral = 0.0; - for(int i = 0; i < m_filterlength; i++) { - //integral += v_X[__seek(curpos - i)]; - // does the same as above if we add up along whole filter length - integral += v_X[i]; - } + double integral = 0.0; + for(int i = 0; i < m_filterlength; i++) { + integral += v_X[i]; + } - v_Y[curpos] = ( integral + v_Y[__loop(curpos - 1)] ) / (m_filterlength + 1.0); + v_Y[curpos] = ( integral + v_Y[__loop(curpos - 1)] ) / (m_filterlength + 1.0); + } else { + v_Y[curpos] = value; + v_time[curpos] = time; + } if(pt_peakdetector != 0) pt_peakdetector->update(v_Y[curpos], v_time[curpos]);