The function moving average uses only standard library headers, also uses dynamic memory to allocate the correct size of the array to do the average.
Import the header
#import "filters.h"
Then, create a new instance of the filter and initialize it according to the number of samples required, assuming that all the samples start in 0.
movingAverage mean1;
mean1.numberOfSamples = 100;
mean1.initialize();
The function initialize could be used to test if the memory allocation is successful.
if(mean1.initialize())
{
cout << "Successful initialization" << endl;
}
else
{
cout<< "No memory remaining" << endl;
return 0
}
The function mean() will return the average of the data samples:
cout << mean1.mean(1);
See testMoving.cpp for a short implementation.