Filtering out a flow of numbers
Hi there,
I was using a ultrasonic sensor to control the position of a video. The thing is that the sensor sends a "jitterish" flow of numbers so the image keeps coming back and forth fast.
Does anyone know how I can flatten it so instead of getting for example 197, 198, 196, 197, and so on, to just get like a median of 197, in this case. But I need it in real time so I don't want to calculate the actual median.
Any ideas?
thank you,
ygreq
If you look at the Extras - Examples - Latest you can find a sensor tamer. It might help.
Hi
This is a common issue, and the forum is replete with various solutions. You even mentioned one yourself - the [zl median] object; look at the helpfiles for the [zl] group of objects, and search this forum for 'smoothing'.
If you're using Arduino, the following code snippet will allow you to average data before it gets to Max:
int samples=10;//sample rate
int inVal;//pin reading
int inPin = 0;//this is your input pin
//place the following inside your loop function, where you are reading the input voltage
for (int i=0; i
{
inVal += analogRead(inPin); //take ten readings and total them
}
inVal /= samples;//divide total by 10 = average
but you can just as easily do this in Max using the [zl] objects - kneel and worship the mighty [zl]!
Brendan
Hey guys,
Thank you for your input!
@grizzle. From what I know Extras is filled with stuff yourself put there, not Max 5 by itself. So may I ask you what is the name of the patch in the extras you have so I can search it on the net!
@n00b_meister. I will have a look on the internet. I didn't know how exactly to formulate what I was to search for. I'll try "smoothing" :D. I'll let you know how that will work out. In relation to medians, I would have to consider a time period and that would mean less fast final output.
I actually use 4 ultrasonic sensors, and I don't want to meddle into that sketch as I just made it work fast enough with all these 4 sensors. And I am not that good in that language yet :( (here is the thread on arduino forum: http://arduino.cc/forum/index.php/topic,65751.0.html)
I was thinking of an algorithm that would not output if jitters a little but output if it changes a lot (when you actually change the distance the sensor is measuring). But it should still react fast enough! I was thinking more as a [change] object for numbers that jitter a little.
Simply put, [change] doesn't output if the input numbers do not change, right? What if it would not output if the input numbers do not change more than -20 or +20?
This is the logic! Now how do I do it? And will it work? :)
Thank you once again
To filter jitter of range X, divide the input by X (integer), use [change] and scale back multiplying with X.
@grizzle. I found the patch you mentioned. I don't quite understand it, but I surely will try it some more and check results.
@n00b_meister. I checked the forum looking for "smoothing". Interesting results indeed! I will copy what I found at the end of this post.
@broc. I will try to test your equation as well for sure!
Thank you so much guys!!!!
ygreq