Object to measure velocity and quantity of data change

Augustine Bannatyne - Leudar's icon

Hi, I am working on a 3D audio effect in which an object moves sounds in 3D space . Im trying to get a sound effect to come from an arduino that depends on how fast the object is moving ( a kind of swooshing sound) and which direction its pointing. The data from the arduino/accelerometer is always changing at the same rate (according to sample rate) but in its resting state this might just be 88.1, 88.2, 88.1 etc etc depending on the direction the object is pointing. When moving the values change according to the coordinates on the accelerometer so might go 88,5, 99. 180, 223 etc etc depending on where the object is pointing. I want a sound effect to come in but depending on how fast the rotation is so a slow gesture - a gentle swish - a very fast gesture a louder swooosh. So this is not just about the velocity of data change (which is constant re sample rate anyway) as much as how much it is changing and how quickly. Is there a way of measuring the velocity and quantity of Data change ? For example if we take 0 to mean very slow (stopped) and 100 as very fast :

if a value changes from 85 ° - 320 ° - in 1 second it puts out a value of 100 (meaning fast)

If a the velocity varies - eg the value intially goes from 85 ° - 320 ° quickly in 1 second then crawls back to 85 ° in 4 seconds - it puts out 100 at first part of the gesture and then 25 for the slower part of the gesture. Any ideas ? Hope this makes sense .....

Floating Point's icon

here's an example of extracting velocity and acceleration information from position: it just uses subtraction of previous sample-- you may want to look into more sophisticated techniques, but this illustrates the basic principle.

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

you should also search for data smoothing in this forum-- there's plenty of examples of cleaning up a noisy signal

Augustine Bannatyne - Leudar's icon

Thanks floating point - Im good with smoothing (f0.smooth etc) ll have a look at your patch

Augustine Bannatyne - Leudar's icon

Floating point this is perfect, just what I needed - thankyou.