cleaning up arduino.getAnalog() input data

I have three analog inputs coming into the arduino for x and y coordinates and the third for transparency. I can place the movie where I want in the screen using the potentiometers.

the inputs jitter a bit and ocassionally jump way out of range for perhaps only one read. So the picture kind of shimmies and occassionaly jumps all over the window.

Is there a function to _smoth_ or average and eleminate highs and lows that are way out of the average so to speak of the arduino.getAnalog() input?

  
  
// display the movie  
  
ofNoFill();  
ofSetColor(255,255,255,ofMap(arduino.getAnalog(2),0,1023,0,255));  
jmov.draw(arduino.getAnalog(0),arduino.getAnalog(1), 400,  300);  
  

Thanks, - jeffa

no, you’ll need to do that by yourself. but seems like a good feature to implement : )

you can just do a running average of the last values and use that instead of the actual output from the pots to do a super basic filter.

i posted some time ago a really simple addon to use opencv kalman filter that is a really good way to filter this kind of data. there’s also some other solutions for a similar problem in this post:

http://forum.openframeworks.cc/t/iphone—accelerometer-peak-detection/2256/7

or, you can use this technique for smoothing:

in .h file:

float smoothValue;

in setup():

smoothValue = 0;

in arduinoUpdate():

smoothValue = 0.95f * smoothValue + 0.05f * ard.getAnalog();

(you can adjust the values 0.95 and 0.05 to something else… they just have to add to 1.0). this is smoothing via mixing (taking some pct of the smoothed value and some pct of the target).

hope that helps!

zach