This code is useful to smooth noisy sensor signals. It does not use much memory.
alpha is the smoothing constant which must be between 0 and 1. An alpha of 0.01 gives smoothing similar to averaging 100 readings.
void loop() {
raw = analogRead(sensorPin);
average = alpha * raw + (1-alpha) * average; //exponential smoothing
Serial.println(average);
delay(1); // delay in between reads for stability
}
That doesn't work the way you say. When I read pin A0 on my Duemilanove and print the raw value, it prints 506 or 507, so the average is 506.5.
With your code and an alpha of .01, it takes about two seconds to settle down to 408. This is not even close to the average of 100 readings.