## change object - detect multiple changes

Feb 15 2015 | 2:53 am
Hi,
Im trying to detect when a number changes, but only when it has changed 10 times within a period of time.
I'm thinking change object, thresh and/or zl queue could be used to do this, but im struggling to make it work.
For instance, I would like to ignore when there are multiple occurrences of the same number
49 48 49 48 49 48 49 48 49 48 49 48
But if there are 10 different numbers within a given period, I would like to recognise this - e.g.
48 49 50 51 52 53 54 55 56 57 58 59 60
Here is a patch to explain more clearly.
Would be grateful if anyone has any interesting ways of getting around this problem.
Cheers
N

• Feb 15 2015 | 4:42 am
Here's one way.
• Feb 15 2015 | 3:03 pm
From the other thread I know that you are looking for data reduction (in both amount and speed). So you could think about it as smoothing as well. In your case a simple average of a block of numbers could be sufficient:
If you are more interested in avoiding big jumps between output values you could refer to a moving average approach. Advantage is smaller jumps, disadvantage your actual output value might be further away from your current data set (as it can take a longer "history" of data into account)
• Feb 16 2015 | 5:02 pm
Building on what Jan said: you might also try a median filter. It is unaffected by extreme outliers and, if using an odd length, always produces a value which is on the stream. (e.g. Zl.stream 9 -> zl.median)
Posting from my phone, so can't check out other poster's solution, but you can find out whether a list has any doubled values by sorting it and then comparing it to a rotated by 1 version, then looking for ones. Something like zl.stream 12 into zl.sort into zl.rot 1 with sorted version into vexpr \$i1==\$i2 into zl.sum into == 0. That should be true IFF there are no repeated values.
• Feb 17 2015 | 10:43 pm
I've tried each one of these examples and they all work really well and I've learnt quite a few new things along the way as well. Many thanks.