SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
Public Member Functions | Protected Attributes | List of all members
MovingAverage< Type > Class Template Reference

#include <movingaverage.h>

Public Member Functions

 MovingAverage (int historySize, Type initial)
 
void resize (int historySize, Type initial)
 
void feed (Type value)
 
void fill (Type value)
 
Type average () const
 
Type sum () const
 
int historySize () const
 

Protected Attributes

std::vector< Type > m_history
 
Type m_sum
 
uint32_t m_index
 

Detailed Description

template<typename Type>
class MovingAverage< Type >

Definition at line 9 of file movingaverage.h.

Constructor & Destructor Documentation

◆ MovingAverage()

template<typename Type>
MovingAverage< Type >::MovingAverage ( int  historySize,
Type  initial 
)
inline

Definition at line 11 of file movingaverage.h.

11  : m_index(0)
12  {
13  resize(historySize, initial);
14  }
uint32_t m_index
Definition: movingaverage.h:61
int historySize() const
Definition: movingaverage.h:53
void resize(int historySize, Type initial)
Definition: movingaverage.h:16

Member Function Documentation

◆ average()

template<typename Type>
Type MovingAverage< Type >::average ( ) const
inline

Definition at line 43 of file movingaverage.h.

Referenced by UDPSink::feed(), MagAGC::feedAndGetValue(), AGC::getAverage(), UDPSource::modulateSample(), UDPSource::pull(), and UDPSinkGUI::tick().

44  {
45  return m_sum / (Type) m_history.size();
46  }
std::vector< Type > m_history
Definition: movingaverage.h:59
+ Here is the caller graph for this function:

◆ feed()

template<typename Type>
void MovingAverage< Type >::feed ( Type  value)
inline

Definition at line 24 of file movingaverage.h.

Referenced by UDPSink::feed(), MagAGC::feedAndGetValue(), UDPSource::modulateSample(), UDPSource::pull(), and UDPSinkGUI::tick().

25  {
26  Type& oldest = m_history[m_index];
27  m_sum += value - oldest;
28  oldest = value;
29 
30  if (m_index < m_history.size() - 1) {
31  m_index++;
32  } else {
33  m_index = 0;
34  }
35  }
uint32_t m_index
Definition: movingaverage.h:61
std::vector< Type > m_history
Definition: movingaverage.h:59
+ Here is the caller graph for this function:

◆ fill()

template<typename Type>
void MovingAverage< Type >::fill ( Type  value)
inline

Definition at line 37 of file movingaverage.h.

Referenced by MagAGC::resize(), and MagAGC::setOrder().

38  {
39  std::fill(m_history.begin(), m_history.end(), value);
40  m_sum = (Type) m_history.size() * value;
41  }
std::vector< Type > m_history
Definition: movingaverage.h:59
+ Here is the caller graph for this function:

◆ historySize()

template<typename Type>
int MovingAverage< Type >::historySize ( ) const
inline

Definition at line 53 of file movingaverage.h.

54  {
55  return m_history.size();
56  }
std::vector< Type > m_history
Definition: movingaverage.h:59

◆ resize()

template<typename Type>
void MovingAverage< Type >::resize ( int  historySize,
Type  initial 
)
inline

Definition at line 16 of file movingaverage.h.

Referenced by UDPSink::applySettings(), UDPSource::applySettings(), MovingAverage< double >::MovingAverage(), and AGC::resize().

17  {
18  m_history.resize(historySize);
19  std::fill(m_history.begin(), m_history.end(), initial);
20  m_sum = (Type) m_history.size() * initial;
21  m_index = 0;
22  }
uint32_t m_index
Definition: movingaverage.h:61
int historySize() const
Definition: movingaverage.h:53
std::vector< Type > m_history
Definition: movingaverage.h:59
+ Here is the caller graph for this function:

◆ sum()

template<typename Type>
Type MovingAverage< Type >::sum ( ) const
inline

Definition at line 48 of file movingaverage.h.

49  {
50  return m_sum;
51  }

Member Data Documentation

◆ m_history

template<typename Type>
std::vector<Type> MovingAverage< Type >::m_history
protected

◆ m_index

template<typename Type>
uint32_t MovingAverage< Type >::m_index
protected

◆ m_sum

template<typename Type>
Type MovingAverage< Type >::m_sum
protected

The documentation for this class was generated from the following file: