noise filtering from incoming list

jee won kim's icon

Hello, forum!
I am getting incoming data from arduino.
The sensor data is very noisy and I want to cancel out the noise data.
I attached a picture and you can see that the meaningful data is under noise data incoming.
The thick black bars are only meaningful datas.
How can I filter out the noisy data from incoming list?

Thank you!

Jean-Francois Charles's icon

[slide] might be an option. Also check in Max, menu Extras -> ExamplesOverview -> Tab "Latest" -> sensor-tamer.help, but it's really useful only if you want to use data to trigger events (not for tracing a value...)

Peter McCulloch's icon

Median filtering can also be helpful because it is resistant to outlying values. A combination of zl.stream 7 -> zl.median will do for a single value.

Jean-Francois Charles's icon

I like this one, Peter!

jee won kim's icon

Thank you all!
Combination of [slide] and [zl.median] worked for me!
I smoothed out the incoming list with [slide] then figured out median number out of it.
And then I compared the median with the incoming list filtered from slide in order to trigger an action.
I tried zl stream but I found slide work better in this case. Maybe zl stream 50 was too much. I do not know.

Thank you anyway!

Peter McCulloch's icon

50 is likely to be too much because that's going to introduce a lot of latency. When you use zl.median, you probably want to feed it a list that has an odd-numbered length. That way, the output is guaranteed to be in the input data (for even-numbered lengths, you take the average of the two center elements).

I would recommend trying something like zl.stream 5 (or 7) -> zl.median -> slide (optional). The median doesn't need to be very large; its main purpose is to remove spurious spikes. Slide is there to smooth out the sometimes blocky output of the median if desired.

jee won kim's icon

cool, i will try that!

Peter McCulloch's icon

One other thing: if you're using slide, it's probably good to make sure that you're reading data at a regular rate because it will smooth over N inputs, not over time. (and since you want it smooth over time, that's where you could use metro to force it to output more regularly)

HTH!

jee won kim's icon

got it! I will let you know what I come up with. Thanks a lot!!