how to collect peak values from a live input stream

jiji's icon

I'm measuring abdominal movement from breath using a stretch sensor and want to capture:
1. the maximum stretch value caused by each breath
2. the time between each of these peaks.
Does anyone know how I can collect each of these maximum values from a live input stream?
I am comparing each peak and time value with previous values to trigger an audio response and taking an average of both value types to trigger an output at the end of each participant's session.

brendan mccloskey's icon

Here's a (late-night) patch to evaluate peaks in a number stream; I've added a [timer] object, but it's not implemented correctly - need sleep will check again in the morning

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

Brendan

Chris Muir's icon

Maybe some combination of peak and trough that get reset by some thresholds being crossed?

jiji's icon

Brendan, that's looking good, thanks! The timer and max values seem spot on. I'm wondering though how to collect the max values, keeping them linked to the corresponding timer value so I can trigger audio that rates the depth and pace of breath and ultimately measure the average depth and pace. There will probably be around 25 of them (from approx 25 breaths over a 2 minute period). Thanks again.

brendan mccloskey's icon

Again, forgive the messy logic, but here's a patch that collects the relevant data in a coll:

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

Brendan

brendan mccloskey's icon
jiji's icon

beautiful work!! I just want to check, I'm wanting to calculate an average value over the first ten values (max and time) and then use this average value to work out the variance against other subsequent max and time values over the 2 minute period. Can I access the values stored int the report for these real time calculations? Thanks again.

brendan mccloskey's icon

yeah, you can poll the [coll]; there's a message you can send, requesting index# and element value, then just use one of the [zl] objects, [zl mean] i think, to work out averages
Brendan

brendan mccloskey's icon

ps

MIB has improved my patch, including a very tasty GUI:

Brendan

jiji's icon

This is mega Brendan thanks! There's a lot for me to digest here - I'm learning about lots of new objects and stuff just trying to keep up with your suggestions. Anyway, off to bed now I'll get back to your patch tomorrow.