From 38337f1333532fa8592dcabddf640dc1861febf2 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 15 Jan 2017 11:26:11 +0100 Subject: [PATCH] Moving average fixes --- CMakeLists.txt | 1 - sdrbase/dsp/movingaverage.cpp | 1 - sdrbase/dsp/movingaverage.h | 22 ++++++++-------------- 3 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 sdrbase/dsp/movingaverage.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 17374ad4b..5b07ed716 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,7 +116,6 @@ set(sdrbase_SOURCES sdrbase/dsp/interpolator.cpp sdrbase/dsp/hbfiltertraits.cpp sdrbase/dsp/lowpass.cpp - sdrbase/dsp/movingaverage.cpp sdrbase/dsp/nco.cpp sdrbase/dsp/ncof.cpp sdrbase/dsp/pidcontroller.cpp diff --git a/sdrbase/dsp/movingaverage.cpp b/sdrbase/dsp/movingaverage.cpp deleted file mode 100644 index dcf8d5599..000000000 --- a/sdrbase/dsp/movingaverage.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "dsp/movingaverage.h" diff --git a/sdrbase/dsp/movingaverage.h b/sdrbase/dsp/movingaverage.h index 6d1199f98..8f97bfdd1 100644 --- a/sdrbase/dsp/movingaverage.h +++ b/sdrbase/dsp/movingaverage.h @@ -3,6 +3,7 @@ #include #include +#include #include "dsp/dsptypes.h" template class MovingAverage { @@ -24,11 +25,7 @@ public: void resize(int historySize, Type initial) { m_history.resize(historySize); - - for(size_t i = 0; i < m_history.size(); i++) { - m_history[i] = initial; - } - + std::fill(m_history.begin(), m_history.end(), initial); m_sum = (Type) m_history.size() * initial; m_index = 0; } @@ -39,19 +36,16 @@ public: m_sum += value - oldest; oldest = value; - m_index++; - - if(m_index >= m_history.size()) { - m_index = 0; - } + if (m_index < m_history.size()) { + m_index++; + } else { + m_index = 0; + } } void fill(Type value) { - for(size_t i = 0; i < m_history.size(); i++) { - m_history[i] = value; - } - + std::fill(m_history.begin(), m_history.end(), value); m_sum = (Type) m_history.size() * value; }