...that deal with pure data
You are not logged in.
Hi,
I've made a simple patch that calls a video clip when an analog reading form pduino is below a certain value and calls another clip when the reading is above another certain value - making the analog reading act as a switch.
It works fine using a potentiometer but I need to use an LDR, which is giving extrememly jumpy readings, which I need to smooth out. I tried splicing in the arduino Smoothing example into the Standard Firmata example but that didn't seem to work. It seems, for this and future projects, it would be really handy to be able to set up an array inside my pd patch that could collect and average out a number of readings but I'm stumped on how to do this and can't find anything already online.
Anyone know how I can smooth out this sensor reading... before a college tutorial on Tuesday?
Thanks in advance!
Offline
There are several ways of doing this. One option would be to use the [mean] object in Pd-extended, another would be to write all the numbers into an array with [tabwrite] then find the mean value by yourself at whatever interval you need. And I guess that also [line] could do the trick in certain conditions.
Is this what you were looking for?
Last edited by guido (2011-10-09 19:23:07)
Offline
Hi,
Thanks for the pointers. What I've done so far is used the [mean] object with a [metro] to clear the total at quite a fast interval. Seems to be helping - although, I think for my purposes, I should eventually learn the ins and outs of [tabwrite].
Thanks again
Offline
This simple patch shows how to get the mean value with [tabread]. It has to be modified in order to be effective, but it works as a starting point. You can easily change the behaviour of the patch and calculate the mean value every n values instead of a fixed time interval. Have a look.
Last edited by guido (2011-10-10 13:02:34)
Offline
Thanks so much!
This seems an elegant solution.
I'm attaching a further development of how I solved the particular problem I was having - which was that the analog sensor reading kept jumping to zero, a few times every second. I used [moses] object to create a kind of gate that would stop the zero reading from affecting the output. It's possible that the [mean] here is now superfluous, not sure.
For this patch to be useful, one would have to have the particular hardware glitch that I was having but I think it's probably not uncommon with cheap LDRs and, in any case, you may find a beginner's solution to this particular problem amusing.
Thanks again for the above patch though, I'll be adapting for a lots of projects, I'm sure.
Offline
You could also implement a simple passive lowpass filter from the output of your LDR, this would attenuate the high frequency changes and, ultimately smooth the analog signal arriving in PureData. just a simple resistor-capacitor network would do the trick, check google for a calculator depending on your cut-off frequency.
Of course though, the formula is
Fc = 1 / 2pi*R*C
I realise this is an old thread, but thought i would just add this for anyone else having issues.
Cheers
Offline