I am measuring the velocity v and the acceleration delta v / t. For the velocity, I collect samples for 100 ms before displaying the average of those samples. For the acceleration however I only store the last value for v in order to get delta v. The result is that the displayed acceleration value is spiky and unreliable.
static float v, prev_v;
static unsigned int n;
static unsigned long lastTime;
v += measure();
n++;
if((millis() - lastTime) > 100){
Serial.print(" v = ");
Serial.println(v / n);
Serial.print("a = ");
Serial.println(v / n - prev_v);
prev_v = v / n;
v = 0;
n = 0;
lastTime = millis();
}
Is there a way to also get the average value for the acceleration?
Any tips are welcome!