Comparing number difference over time

Benjamin Penwell's icon

I'm making a patch to work with a gyroscope and I'm trying to do something that is conceptually easy but I just can't figure out how to do it. Basically I want to trigger events if certain readings move quickly enough - so if a value increases by say 300 or more in less than 1000ms, it will trigger a bang, but if the value increases that amount in more than 1000ms, nothing will be triggered. The starting/ending values don't matter, so if it goes from 300-650 it will trigger, or 800-1200 it will trigger. I need to set it up so that it can happen at any time, which means I can't trigger something beforehand to compare the values within that time range, it needs to be dynamic. Any thoughts?

Roman Thilenius's icon

calculating the running whatever of values incoming during a time frame in milliseconds can be a pita, and the more exact you want the time frames to be, the more CPU it eats.

so it might be the best to convert it to an audio signal, then you can build it around average~ among others.

for operation of numbers you might want to start with zl.stream

Bill 2's icon

I don't know how much of a pita this is or how much cpu it eats, but I think it does what you want:

Max Patch
Copy patch and select New From Clipboard in Max.

Benjamin Penwell's icon

Thanks for the replies Roman and Bill. I'll have to look at that patcher and test it out but it looks like a promising start to what I'm trying to do. It's funny that one of you mentioned zl.stream and the other used zl.group because I was talking to my friend in my electronic music class the other day and I said out loud "I guarantee whatever I'm trying to do uses some sort of zl object but I just can't figure it out".

Praveen Sinha's icon

Ok i wanted to do something similar but i used a pipe thing to check for a difference in the values after that much interval - and then test it with a threshold value. I made it to recognise a hand flip on a kinect.
Check the patch for hints i guess.

fast change.maxpat
Max Patch
Fast Change.