mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-16 13:21:50 -05:00
Moving average fixes
This commit is contained in:
parent
618f302aad
commit
38337f1333
@ -116,7 +116,6 @@ set(sdrbase_SOURCES
|
|||||||
sdrbase/dsp/interpolator.cpp
|
sdrbase/dsp/interpolator.cpp
|
||||||
sdrbase/dsp/hbfiltertraits.cpp
|
sdrbase/dsp/hbfiltertraits.cpp
|
||||||
sdrbase/dsp/lowpass.cpp
|
sdrbase/dsp/lowpass.cpp
|
||||||
sdrbase/dsp/movingaverage.cpp
|
|
||||||
sdrbase/dsp/nco.cpp
|
sdrbase/dsp/nco.cpp
|
||||||
sdrbase/dsp/ncof.cpp
|
sdrbase/dsp/ncof.cpp
|
||||||
sdrbase/dsp/pidcontroller.cpp
|
sdrbase/dsp/pidcontroller.cpp
|
||||||
|
@ -1 +0,0 @@
|
|||||||
#include "dsp/movingaverage.h"
|
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
#include "dsp/dsptypes.h"
|
#include "dsp/dsptypes.h"
|
||||||
|
|
||||||
template<class Type> class MovingAverage {
|
template<class Type> class MovingAverage {
|
||||||
@ -24,11 +25,7 @@ public:
|
|||||||
void resize(int historySize, Type initial)
|
void resize(int historySize, Type initial)
|
||||||
{
|
{
|
||||||
m_history.resize(historySize);
|
m_history.resize(historySize);
|
||||||
|
std::fill(m_history.begin(), m_history.end(), initial);
|
||||||
for(size_t i = 0; i < m_history.size(); i++) {
|
|
||||||
m_history[i] = initial;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sum = (Type) m_history.size() * initial;
|
m_sum = (Type) m_history.size() * initial;
|
||||||
m_index = 0;
|
m_index = 0;
|
||||||
}
|
}
|
||||||
@ -39,19 +36,16 @@ public:
|
|||||||
m_sum += value - oldest;
|
m_sum += value - oldest;
|
||||||
oldest = value;
|
oldest = value;
|
||||||
|
|
||||||
m_index++;
|
if (m_index < m_history.size()) {
|
||||||
|
m_index++;
|
||||||
if(m_index >= m_history.size()) {
|
} else {
|
||||||
m_index = 0;
|
m_index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill(Type value)
|
void fill(Type value)
|
||||||
{
|
{
|
||||||
for(size_t i = 0; i < m_history.size(); i++) {
|
std::fill(m_history.begin(), m_history.end(), value);
|
||||||
m_history[i] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_sum = (Type) m_history.size() * value;
|
m_sum = (Type) m_history.size() * value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user