comparing successive message values

Jacob's icon

Hello,

Is there an object or combination of objects that can compare two successive messages coming in from the same source?

I want to compare the difference between two successive sensor readings and filter out ones with a difference greater than 10 (in the sensor's value units) and route those values somewhere else.

It sounds simple, but I'm struggling finding a way to code this in Max. Any hints would be greatly appreciated

Thanks!
-J

Roman Thilenius's icon

the difference between two numbers is the most simple case: you´d just feed the input to both inlets of [- 0.]

for comparing symbols and/or comparing more complicated stuff, which might require [if] or [expr] at a point, you can use a register such as [i] or [zl reg] to delay message #7 for one step, in order to compare it with #6.

-110

Peter Castine's icon

It's quite simple to set up a simple [-] object to compare two successive values. The trick is to understand the full implications of right-to-left ordering.

The following patch isn't necessarily the smallest or fastest doing what it does, but it is arguably the most "Max-like" approach. The comparison is essentially done by a single object; it takes a few more for the routing.

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

I'm assuming integer input; a few trivial changes are needed for working with floats (one of which Roman alluded to).