Creating averages from a list.

Omar Shabbar's icon

Hey there, still relatively new to MAX and wondering if there's an object that exists that could make my life easier.

I have a list of incoming values that is constantly changing. I'm looking to get the averages of each of the values in the list over a 100ms timeframe with a bang.

Right now I'm using the unpack object and sending each value out to its own mean object.

Is there a way to get the averages of all of those values (not the values together, the values changing over time) without unpacking them?

I've already looked at the zl and vexpr objects to no avail.

Cheers,
Omar

Roman Thilenius's icon

i dont think so.

when at least the length of the list is known, you are fine with unpack.

what i wonder more is if [mean] really gives you want you want? because taking the output every 100ms is not the running average, in case you wanted that.

Andy Maskell's icon

There are lots of methods for doing this depending on exactly what you are wanting to average. Here are two suggestions for starters:

The left hand thread collects a list of values for 100ms and then calculates the average of those values before starting the cycle again. The output is only updated every 100ms.

The right hand thread generates a continuous running average of all the values input before the [mean] object is reset at 100ms intervals. The output is updated with each new incoming value with the calculation being reset every 100ms.

The [onebang] in there is not strictly necessary in these examples but I put it there so that you could see how it might come in handy for other scenarios. In this case, it essentially throttles the [metro] and blocks the mean calculations unless new incoming data has arrived.

You could combine variants of this in a number of ways depending on how you want to slice up and average the incoming values. You could, for example, replace the [metro] with a [counter] if you wanted to average a fixed number of values or combine both methods together to compute the last x values that arrive each 100ms.

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

double_UG's icon

Please provide at least 10 characters

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

Source Audio's icon

..........
I'd use coll to capture list input

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

Omar Shabbar's icon

Amazing, thank you for all of the help. I think that I have solved it with the Double_UG patch above.

Thanks again all!