signal_processing.cpp
Go to the documentation of this file.
1 #include "signal_processing.h"
2 
3 namespace argos {
4 
5  /****************************************/
6  /****************************************/
7 
9  m_unCounter(0),
10  m_fMean(0.0f),
11  m_fSumOfSquareDiff(0.0f) {}
12 
13  /****************************************/
14  /****************************************/
15 
16  void CStats::Append(Real f_value) {
17  /*
18  * Algorithm taken from:
19  * http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm
20  */
21  ++m_unCounter;
22  Real fDelta = f_value - m_fMean;
23  m_fMean += fDelta / static_cast<Real>(m_unCounter);
24  m_fSumOfSquareDiff += fDelta * (f_value - m_fMean);
25  }
26 
27  /****************************************/
28  /****************************************/
29 
31  return m_unCounter > 1 ?
32  (m_fSumOfSquareDiff / static_cast<Real>(m_unCounter - 1))
33  :
34  0.0f;
35  }
36 
37  /****************************************/
38  /****************************************/
39 
41  m_fSmoothingFactor(f_smoothing_factor),
42  m_bInitialized(false) {}
43 
44  /****************************************/
45  /****************************************/
46 
48  if(m_bInitialized) {
49  m_fPreviousOutput = f_input + m_fSmoothingFactor * (m_fPreviousOutput - f_input);
50  }
51  else {
52  m_fPreviousOutput = f_input;
53  m_bInitialized = true;
54  }
55  return m_fPreviousOutput;
56  }
57 
58  /****************************************/
59  /****************************************/
60 
62  m_bInitialized = false;
63  }
64 
65  /****************************************/
66  /****************************************/
67 
68 }
float Real
Collects all ARGoS code.
Definition: datatypes.h:39
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
Real GetVariance() const
Returns the variance of the signal.
void Append(Real f_value)
Appends a new piece of data and recalculates the statistics.
Real Filter(Real f_input)
Applies the filter to the given value.
void Reset()
Resets the filter.
CRCLowPassFilter(Real f_smoothing_factor)
Class constructor.