Moving Average

Dependents:   MovingAverage_HelloWorld Levitator EMG_Realtime_Filter EMG_Calibration ... more

Fork of MoyenneMobile by Alexandre Proulx

Embed: (wiki syntax)

« Back to documentation index

MovingAverage< T > Class Template Reference

MovingAverage< T > Class Template Reference

class of moving average Example: More...

#include <MovingAverage.h>

Public Member Functions

 MovingAverage (unsigned char maxLength, T defaultValue)
 Create moving average.
GetAverage ()
 Get the value of the moving average.
void Insert (T value)
 Insert a element in moving average.

Detailed Description

template<class T>
class MovingAverage< T >

class of moving average Example:

 #include "mbed.h"
 #include "MovingAverage.h"
 #define NSAMPLE 100
 Ticker flipperADC;
 AnalogIn   ain(A0);
 MovingAverage <float>vavg(NSAMPLE,0.0);
 void flipADC()
 {
     vavg.Insert(ain.read());
 }
 int main()
 { 
   flipperADC.attach_us(&flipADC, 10000);
   while (true) 
      printf("analog= %f \r\n",vavg.GetAverage()); 
 }

Definition at line 42 of file MovingAverage.h.


Constructor & Destructor Documentation

MovingAverage ( unsigned char  maxLength,
defaultValue 
)

Create moving average.

Parameters:
maxLengthis length of moving average
valueis initial value

Definition at line 68 of file MovingAverage.h.


Member Function Documentation

T GetAverage (  )

Get the value of the moving average.

Returns:
value of the moving average

Definition at line 81 of file MovingAverage.h.

void Insert ( value )

Insert a element in moving average.

Parameters:
valueis the element inserted in moving average

Definition at line 87 of file MovingAverage.h.