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
MovingAverageUtil< T, Total, N > Class Template Reference

#include <movingaverage.h>

Public Member Functions

 MovingAverageUtil ()
 
void reset ()
 
void operator() (T sample)
 
double asDouble () const
 
float asFloat () const
 
 operator T () const
 
instantAverage () const
 

Private Attributes

m_samples [N]
 
int m_num_samples
 
unsigned int m_index
 
Total m_total
 

Detailed Description

template<typename T, typename Total, int N>
class MovingAverageUtil< T, Total, N >

Definition at line 27 of file movingaverage.h.

Constructor & Destructor Documentation

◆ MovingAverageUtil()

template<typename T, typename Total, int N>
MovingAverageUtil< T, Total, N >::MovingAverageUtil ( )
inline

Definition at line 30 of file movingaverage.h.

31  : m_num_samples(0), m_index(0), m_total(0)
32  { }
unsigned int m_index
Definition: movingaverage.h:65

Member Function Documentation

◆ asDouble()

template<typename T, typename Total, int N>
double MovingAverageUtil< T, Total, N >::asDouble ( ) const
inline

◆ asFloat()

template<typename T, typename Total, int N>
float MovingAverageUtil< T, Total, N >::asFloat ( ) const
inline

Definition at line 58 of file movingaverage.h.

58 { return ((float)m_total) / N; }

◆ instantAverage()

template<typename T, typename Total, int N>
T MovingAverageUtil< T, Total, N >::instantAverage ( ) const
inline

Definition at line 60 of file movingaverage.h.

60 { return m_total / (m_num_samples == 0 ? 1 : m_num_samples); }

◆ operator T()

template<typename T, typename Total, int N>
MovingAverageUtil< T, Total, N >::operator T ( ) const
inline

Definition at line 59 of file movingaverage.h.

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

59 { return m_total / N; }

◆ operator()()

template<typename T, typename Total, int N>
void MovingAverageUtil< T, Total, N >::operator() ( sample)
inline

Definition at line 41 of file movingaverage.h.

42  {
43  if (m_num_samples < N) // fill up
44  {
45  m_samples[m_num_samples++] = sample;
46  m_total += sample;
47  }
48  else // roll
49  {
50  T& oldest = m_samples[m_index];
51  m_total += sample - oldest;
52  oldest = sample;
53  m_index = (m_index + 1) % N;
54  }
55  }
unsigned int m_index
Definition: movingaverage.h:65

◆ reset()

template<typename T, typename Total, int N>
void MovingAverageUtil< T, Total, N >::reset ( )
inline

Definition at line 34 of file movingaverage.h.

Referenced by NFMDemod::applySettings(), DSPDeviceSourceEngine::handleInputMessages(), MovingAverageUtilVar< T, Total >::resize(), and DSPDeviceMIMOEngine::SourceCorrection::SourceCorrection().

35  {
36  m_num_samples = 0;
37  m_index = 0;
38  m_total = 0;
39  }
unsigned int m_index
Definition: movingaverage.h:65
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_index

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

◆ m_num_samples

template<typename T, typename Total, int N>
int MovingAverageUtil< T, Total, N >::m_num_samples
private

◆ m_samples

template<typename T, typename Total, int N>
T MovingAverageUtil< T, Total, N >::m_samples[N]
private

◆ m_total

template<typename T, typename Total, int N>
Total MovingAverageUtil< T, Total, N >::m_total
private

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