I wrote some C++ code that facilitates the use of moving average filters and can be used with Arduino to de-noise input signals. The code can be found here.
A new instance of MovingAverage is created as follows:
MovingAverage* movingAverage = new MovingAverage(5);
New data is added like this:
double measurement = analogRead(myPin)*scalingFactor;
movingAverage->add(measurement);
and the current average value is retrieved as follows:
movingAverage->getCurrentAverage();
The problem I'm facing is that the operator new fails. On the Arduino IDE, I tried the following code:
#include <new.h>
#include <MovingAverage.h>
MovingAverage * ma = new MovingAverage(10);
void setup() {
}
void loop() {
}
which throws the following error:
MovingAverage/MovingAverage.cpp.o: In function `MovingAverage::MovingAverage(unsigned short)':
.../Electronix/arduino-1.0.2/libraries/MovingAverage/MovingAverage.cpp:19: undefined reference to `operator new[](unsigned int)'
I suspected that this is because of the attempt to dynamically allocate memory in MovingAverage.cpp. I then tried the following:
double * vector = new double[10];
and I got exactly the same error message. This means that new[]
cannot be used in Arduino. Is there some way to work this around?