#include <RunningAverage.h>
Public Member Functions | |
| T | Get () |
| Gives the current running average. | |
| int | GetLength () const |
| Tells the length in samples of this running average filter. | |
| void | Put (T sample) |
| Feeds a sample into the running average filter. | |
| void | Reset () |
| Resets this running average filter. | |
| RunningAverage (int nLength) | |
| Constructor. | |
| ~RunningAverage () | |
| Destructor. | |
Protected Attributes | |
| int | _iPos |
| Store position in the buffer. | |
| int | _nLength |
| Length in samples of the running average filter. | |
| T * | _pBuffer |
| Pointer to the internal buffer used to store the past samples. | |
| T | _sum |
| Up-to-date sum of the past samples. | |
| T | Defines the sample type for the running average. |
Definition at line 45 of file RunningAverage.h.
|
||||||||||
|
Constructor.
Definition at line 85 of file RunningAverage.h. References RunningAverage< T >::_nLength, and RunningAverage< T >::_pBuffer. 00086 : _nLength(nLength), 00087 _sum(0), 00088 _iPos(0) 00089 { 00090 _pBuffer = new T[_nLength]; 00091 memset(_pBuffer, 0, _nLength * sizeof(T)); 00092 };
|
|
|||||||||
|
Destructor.
Definition at line 98 of file RunningAverage.h. References RunningAverage< T >::_pBuffer. 00098 { 00099 delete _pBuffer; 00100 };
|
|
|||||||||
|
Gives the current running average.
Definition at line 145 of file RunningAverage.h. References RunningAverage< T >::_nLength, and RunningAverage< T >::_sum.
|
|
|||||||||
|
Tells the length in samples of this running average filter.
Definition at line 110 of file RunningAverage.h. References RunningAverage< T >::_nLength. 00110 { return _nLength; };
|
|
||||||||||
|
Feeds a sample into the running average filter.
Definition at line 130 of file RunningAverage.h. References RunningAverage< T >::_iPos, RunningAverage< T >::_nLength, RunningAverage< T >::_pBuffer, and RunningAverage< T >::_sum. 00130 { 00131 _sum -= _pBuffer[_iPos]; // Subtract the last sample 00132 _sum += sample; // Add the new sample to the total sum 00133 _pBuffer[_iPos] = sample; // Store the new sample 00134 _iPos = (_iPos+1) % _nLength; // Advance write position 00135 }
|
|
|||||||||
|
Resets this running average filter.
Definition at line 116 of file RunningAverage.h. References RunningAverage< T >::_iPos, RunningAverage< T >::_nLength, RunningAverage< T >::_pBuffer, and RunningAverage< T >::_sum.
|
|
|||||
|
Store position in the buffer.
Definition at line 66 of file RunningAverage.h. Referenced by RunningAverage< T >::Put(), and RunningAverage< T >::Reset(). |
|
|||||
|
Length in samples of the running average filter.
Definition at line 54 of file RunningAverage.h. Referenced by RunningAverage< T >::Get(), RunningAverage< T >::GetLength(), RunningAverage< T >::Put(), RunningAverage< T >::Reset(), and RunningAverage< T >::RunningAverage(). |
|
|||||
|
Pointer to the internal buffer used to store the past samples.
Definition at line 60 of file RunningAverage.h. Referenced by RunningAverage< T >::Put(), RunningAverage< T >::Reset(), RunningAverage< T >::RunningAverage(), and RunningAverage< T >::~RunningAverage(). |
|
|||||
|
Up-to-date sum of the past samples.
Definition at line 72 of file RunningAverage.h. Referenced by RunningAverage< T >::Get(), RunningAverage< T >::Put(), and RunningAverage< T >::Reset(). |
1.4.5