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 | Private Attributes | List of all members
MovingAverageUtilVar< T, Total > Class Template Reference

#include <movingaverage.h>

Public Member Functions

 MovingAverageUtilVar (unsigned int size)
 
void reset ()
 
void resize (unsigned int size)
 
unsigned int size () const
 
void operator() (T sample)
 
double asDouble () const
 
float asFloat () const
 
 operator T () const
 

Private Attributes

std::vector< T > m_samples
 
unsigned int m_num_samples
 
unsigned int m_index
 
Total m_total
 

Detailed Description

template<typename T, typename Total>
class MovingAverageUtilVar< T, Total >

Definition at line 71 of file movingaverage.h.

Constructor & Destructor Documentation

◆ MovingAverageUtilVar()

template<typename T , typename Total >
MovingAverageUtilVar< T, Total >::MovingAverageUtilVar ( unsigned int  size)
inline

Definition at line 74 of file movingaverage.h.

References MovingAverageUtil< T, Total, N >::m_samples.

75  : m_num_samples(0), m_index(0), m_total(0)
76  {
77  m_samples.resize(size);
78  }
unsigned int size() const
Definition: movingaverage.h:93
unsigned int m_index
unsigned int m_num_samples
std::vector< T > m_samples

Member Function Documentation

◆ asDouble()

template<typename T , typename Total >
double MovingAverageUtilVar< T, Total >::asDouble ( ) const
inline

Definition at line 114 of file movingaverage.h.

References MovingAverageUtil< T, Total, N >::m_samples, and MovingAverageUtil< T, Total, N >::m_total.

114 { return ((double)m_total) / m_samples.size(); }
std::vector< T > m_samples

◆ asFloat()

template<typename T , typename Total >
float MovingAverageUtilVar< T, Total >::asFloat ( ) const
inline

Definition at line 115 of file movingaverage.h.

References MovingAverageUtil< T, Total, N >::m_samples, and MovingAverageUtil< T, Total, N >::m_total.

115 { return ((float)m_total) / m_samples.size(); }
std::vector< T > m_samples

◆ operator T()

template<typename T , typename Total >
MovingAverageUtilVar< T, Total >::operator T ( ) const
inline

◆ operator()()

template<typename T , typename Total >
void MovingAverageUtilVar< T, Total >::operator() ( sample)
inline

Definition at line 98 of file movingaverage.h.

References MovingAverageUtil< T, Total, N >::m_index, MovingAverageUtil< T, Total, N >::m_num_samples, MovingAverageUtil< T, Total, N >::m_samples, and MovingAverageUtil< T, Total, N >::m_total.

99  {
100  if (m_num_samples < m_samples.size()) // fill up
101  {
102  m_samples[m_num_samples++] = sample;
103  m_total += sample;
104  }
105  else // roll
106  {
107  T& oldest = m_samples[m_index];
108  m_total += sample - oldest;
109  oldest = sample;
110  m_index = (m_index + 1) % m_samples.size();
111  }
112  }
unsigned int m_index
unsigned int m_num_samples
std::vector< T > m_samples

◆ reset()

template<typename T , typename Total >
void MovingAverageUtilVar< T, Total >::reset ( )
inline

◆ resize()

template<typename T , typename Total >
void MovingAverageUtilVar< T, Total >::resize ( unsigned int  size)
inline

Definition at line 87 of file movingaverage.h.

References MovingAverageUtil< T, Total, N >::m_samples, and MovingAverageUtil< T, Total, N >::reset().

88  {
89  reset();
90  m_samples.resize(size);
91  }
unsigned int size() const
Definition: movingaverage.h:93
std::vector< T > m_samples
+ Here is the call graph for this function:

◆ size()

template<typename T , typename Total >
unsigned int MovingAverageUtilVar< T, Total >::size ( ) const
inline

Definition at line 93 of file movingaverage.h.

References MovingAverageUtil< T, Total, N >::m_samples.

94  {
95  return m_samples.size();
96  }
std::vector< T > m_samples

Member Data Documentation

◆ m_index

template<typename T , typename Total >
unsigned int MovingAverageUtilVar< T, Total >::m_index
private

Definition at line 121 of file movingaverage.h.

◆ m_num_samples

template<typename T , typename Total >
unsigned int MovingAverageUtilVar< T, Total >::m_num_samples
private

Definition at line 120 of file movingaverage.h.

◆ m_samples

template<typename T , typename Total >
std::vector<T> MovingAverageUtilVar< T, Total >::m_samples
private

Definition at line 119 of file movingaverage.h.

◆ m_total

template<typename T , typename Total >
Total MovingAverageUtilVar< T, Total >::m_total
private

Definition at line 122 of file movingaverage.h.


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