Forums > MaxMSP

i need to test whether numbers coming in to my patch are truly random or not

April 29, 2009 | 7:11 pm

hi, i hope maybe someone can help me with a part of my patch :

i am using distance sensors going into an arduino and then into max msp.

max msp then makes sounds in relation to the readings from the sensors

the sensors are on a wall as part of an interactive painting.

when someone stands in front of the sensors they work well, and the numbers that come into max as a result are fairly steady (eg 12, 13, 15, 11, 14, 12…..etc) and max plays the appropriate sound

when no-one stands in front of a sensor they give their maximum range as you would expect and max plays a silent sample. but they also start giving fairly random readings which causes max to play sounds when no one is there.

i have tried many methods to try and stop these random readings but i am still stuck. i have tried different methods of wiring the sensors, changing the arduino code but all to no avail.

i am trying to filter out these random readings in max but have only had partial success so far.

i need to make a small patch to test the range of numbers coming in to max. if the number range is large (sensors are on maximum range and behaving randomly) then i need to stop the numbers influencing the patch but if the range is small and steady (someone is stood in front of a sensor) then i need to use those numbers in the rest of the patch.

i really hope someone can help me as im still fairly new to maxmsp and i am finding it a bit of a struggle

i am using max 4.5

many thanks in advance for any help


April 29, 2009 | 7:50 pm

have a look at this http://maxobjects.com/?v=objects&id_objet=3772


April 29, 2009 | 7:56 pm

hi

many thanks for your reply

i have been trying to use that very lbyl object but it doesnt seem to work too well if the numbers coming in to it are random, it works well with an occasional glitchy number though


April 29, 2009 | 8:02 pm

you say the results you want are 12, 13, 15, 11, 14, 12

do the random numbers fall outside the range of these numbers?


April 29, 2009 | 8:13 pm

hi again

those numbers are just an example of what the readings would be from a sensor if someone stood in front of it and it gave a fairly steady reading. they would fluctuate just a little bit.

for example, if someone stood a bit further away and the sensor still sensed them then the numbers would go up and maybe give results like 180, 182, 183, 182, 179….etc, the sensors give a reading about every 50ms.

when no-one is there they start to give random readings from noise or something (i have tried filtering this out with different wiring setups but have drawn a blank) and i need to stop these random numbers from getting through to the rest of the patch, until someone again walks into the sensor’s path and it starts to give a steady reading again

thanks again



MIB
April 29, 2009 | 9:16 pm

I guess you tried the [mean] object with various settings?? if you [mean] every 20 or 30 numbers you should get a much better result… of course you are going to sacrifice some resolution this way.

– Pasted Max Patch, click to expand. –

April 29, 2009 | 9:28 pm

i might suggest another sensor.

if you can have some kind of wide-field sensor to suggest the (non)presence of a person, then you could "and gate" the proximity sensor with the presence sensor.

alternatively, if the noise is sparse, you could just double up your sensors and block the output if both the two are far apart.

either of these solutions will allow rare false-positives but at a rate much lower than what you’re experiencing now, at least in principle.


April 29, 2009 | 9:48 pm

hi

thanks for your reply

i have tried the mean object as well as an object from the litter package in the max objects database but they dont give very good results as the random numbers coming in make the average of the more steady numbers more innaccurate

i cant quite figure it out but what i am trying to do is get max to look at consecutive numbers coming in and if their average range is continually high then those numbers would be random (ie the sensors are not picking anything up) and they need filtering out. if the average range of the numbers is continually low (about 5) then someone must be stood in front of the sensors and those numbers can then be used in the next part of the patch

many thanks if you can help me, its sending me a bit mad

im using max 4.5 btw


April 29, 2009 | 10:00 pm
flies wrote on Wed, 29 April 2009 22:28
i might suggest another sensor.

if you can have some kind of wide-field sensor to suggest the (non)presence of a person, then you could "and gate" the proximity sensor with the presence sensor.

alternatively, if the noise is sparse, you could just double up your sensors and block the output if both the two are far apart.

either of these solutions will allow rare false-positives but at a rate much lower than what you’re experiencing now, at least in principle.

hi

thanks for this,
i am thinking about maybe using a pir sensor as well (one of those infra red burglar alarm ones) then i could get it to switch all the sounds off if no-one is there, but when it picks up some motion it would turn the sounds back on again.

the only problem i think i would have here is that if someone is sensed by the pir sensor and a distance sensor as well then as i have six distance sensors running that would still leave maybe 4 or 5 sensors giving random number readings (and making sounds i dont want as a result) as they wouldnt be registering any prescence.

im confused, and i have to display this in a few weeks Sad



MIB
April 29, 2009 | 10:33 pm

maybe you could set up a timing patch. if your numbers are "good", someone is definitely standing there (from 10 to 180 or whatever), then do what you do, if the number goes over 180 use a gate to disconnect the sensor from your audio. Then if the reading goes back to your "green" zone start a timer. If the timer reaches a certain time without the sensor numbers going back to "bad"(if you have 1 or 2 solid seconds of good numbers we can assume that someone is there now), switch your gate on, if the numbers go bad reset the timer, leave the gate closed and wait for another good number and start the whole timing thing over again.

I could probably hack something together for in Max 4 (sorry about that) but am at the wrong machine right now…

but then again, I have little experience with sensors…


April 30, 2009 | 10:12 am

The basic problem is your goal is not well-defined. Asking "are these numbers random?" is like asking "are these notes beautiful?", particularly because what you consider "non-random" numbers are also effectively random, just a different flavor of randomness.

What could work well for the numbers you are describing is to use lp.stacey, which I think you have tried, but to use the standard deviation outlet rather than the mean (which is what most people look at). Use a smallish window (say something like [lp.stacey 5] and test the fifth outlet against a threshold of 1.5 or 2. If the standard deviation is below the threshold, open a gate to let your Arduino values through, otherwise close the gate.

You’ll need to experiment to find the best threshold for your input.

PS: I was just building a test patch to demonstrate the technique but Max crashed while I was paste-replacing a multislider Sad I’ve got to get back to work, but let me know if you need a concrete example to get you going.


April 30, 2009 | 6:10 pm
slatepipe wrote on Wed, 29 April 2009 12:11
i have tried many methods to try and stop these random readings but i am still stuck. i have tried different methods of wiring the sensors, changing the arduino code but all to no avail.

Did you put a 10uF capacitor across the power and ground right at the sensor? Those IR distance sensors draw power in a noisy way; which gets ugly when you use multiple sensors.

mz


May 1, 2009 | 5:28 pm
mzed wrote on Thu, 30 April 2009 19:10
slatepipe wrote on Wed, 29 April 2009 12:11
i have tried many methods to try and stop these random readings but i am still stuck. i have tried different methods of wiring the sensors, changing the arduino code but all to no avail.

Did you put a 10uF capacitor across the power and ground right at the sensor? Those IR distance sensors draw power in a noisy way; which gets ugly when you use multiple sensors.

mz

hi
thanks for these replies, i have been busy for the last 2 days and could not get to a computer. i have been told something about the 10uf capacitor by my tutor – it could be something that i will try. can you give me a bit more info on this? i am still learning and am relatively new to electronics. i guess i will have to use a capacitor on every sensor?

many thanks for any further advice Smile


May 1, 2009 | 5:44 pm
Peter Castine wrote on Thu, 30 April 2009 11:12
The basic problem is your goal is not well-defined. Asking "are these numbers random?" is like asking "are these notes beautiful?", particularly because what you consider "non-random" numbers are also effectively random, just a different flavor of randomness.

What could work well for the numbers you are describing is to use lp.stacey, which I think you have tried, but to use the standard deviation outlet rather than the mean (which is what most people look at). Use a smallish window (say something like [lp.stacey 5] and test the fifth outlet against a threshold of 1.5 or 2. If the standard deviation is below the threshold, open a gate to let your Arduino values through, otherwise close the gate.

You’ll need to experiment to find the best threshold for your input.

PS: I was just building a test patch to demonstrate the technique but Max crashed while I was paste-replacing a multislider Sad I’ve got to get back to work, but let me know if you need a concrete example to get you going.

hi there

yes, i have looked at the lp stacey object a little though i am still new with my max knowledge as regards its implementation.

i think the standard deviation thing may be good to work with but i struggle with the patch layout.

if you could show me an example (with max 4.5, sorry) that would be great.

my problem is thus : if numbers are very random (ie no-one is in front of a sensor and the numbers coming in are anything from about 0 to 500) then they need filtering out. if the numbers coming in start to be reasonably steady (ie someone moves in front of a sensor and the sensor starts to give more accurate readings, like eg 99,100,103,100,99,101 etc) then i want to allow them through to the next part of the patch, which will probably be a lbyl object at the moment

i would just like to say that i find the help i have been offered so far on this forum very humbling. thanks


May 1, 2009 | 10:44 pm

hi again

i have made this test filter patch below. it is kind of on the way to what i am looking for but i think some of it may need rearranging. it uses the standard deviation from lp.stacey, if anyone can help add to the patch to steer me in the right direction that would be great


May 3, 2009 | 5:54 pm

That was my basic idea. Now just connect the output of your [< = 5] object to the left inlet of a [gate] and connect the GSwitch’s output to the gate’s right inlet. What comes out of the gate are your "not-quite-so-random random numbers" and the "really really random numbers" never get past.


May 4, 2009 | 3:33 pm

hi again

thanks to everyone for the help

i have tried implementing the enclosed patch into my main patch whic takes the readings from the six sensors. when i hook it into one of the streams of incoming numbers it works fine. however, when i copy it and try to hook it into the number stream from the next sensor i get this windows message "could not get thread local data" error and then max shuts down. i have no idea what this is, can anyone help me (again )

i really thought i had almost sorted it all out and now this problem has occurred Sad

i’ll look into the capacitor issue too


May 4, 2009 | 5:13 pm
slatepipe wrote on Fri, 01 May 2009 10:28
mzed wrote on Thu, 30 April 2009 19:10
slatepipe wrote on Wed, 29 April 2009 12:11
i have tried many methods to try and stop these random readings but i am still stuck.

Did you put a 10uF capacitor across the power and ground right at the sensor?

i have been told something about the 10uf capacitor by my tutor – it could be something that i will try. can you give me a bit more info on this? i am still learning and am relatively new to electronics. i guess i will have to use a capacitor on every sensor?

Yes, a capacitor on every sensor. Don’t worry, they’re cheap.

I did a piece with 32 of these guys, check out Knock on the Sky here:

http://mikezed.com/technology.html

The sensor strobes an IR Led and detects the bouncing light. The blinkin-lights pull a lot of current periodically, more than your Arduino can handle. When you start to have a few of them, it starts to make for a very dirty power supply. Bad power == bad readings. The cap from power to ground tends to smooth out the fluctuations and improve the stability of your readings. Google "smoothing capacitor" for a lot of information.

I went through a lot of effort with 32… external power supply, shielded cable, opamp,… the schematic is on my site. It was massive overkill, but sometimes that’s my engineering philosophy.

mz


May 4, 2009 | 5:17 pm

PS After I did that project, I’ve learned that the best practice is to put the capacitor as close to the sensor as possible.


May 4, 2009 | 6:01 pm

hi there

thanks for this great advice

i will get on with this tomorrow

i currently have my system set up as in 6f here :

http://www.maxbotix.com/MaxSonar-EZ1__FAQ.html.
as in ‘daisy chaining with constantly looping’.

i guess what you are suggesting is to do as it says in part 22, to eliminate dirty power supply? this says to put a resistor on the +5 as well, so with all this i hopefully should get those bad readings filtered out.

as you’ve probably read, i have been trying to filter them out using max and achieved partial success, but have hit a stumbling block with an unknown error

cheers


May 4, 2009 | 11:36 pm
slatepipe wrote on Mon, 04 May 2009 11:01
.
i guess what you are suggesting is to do as it says in part 22, to eliminate dirty power supply? this says to put a resistor on the +5 as well, so with all this i hopefully should get those bad readings filtered out.

That looks like the way. This is a basic low-pass filter, and I think it should help. If the sensors are in serial, like you said, then you might only need one of these.

Unfortunately, I have nothing helpful to say about the Max error. If the patch you attached is crashing, then maybe Peter has an idea? Everything else is vanilla max, and probably solid. (I think Peter’s object is probably just as solid… I was expecting a problem with the serial object, or some such.)

mz


Viewing 21 posts - 1 through 21 (of 21 total)