Help Needed with Scalable Running Average Node


I would like to create a scalable running average block with an input to define the number of samples to average and a clock input to regulate the rate of sampling the input and updating the output I think, I could use a list as the buffer for the number of samples to average, but I do not know how to index into a list or how to set up a list to start with. Does anyone have an example of using a list for a sample buffer that I could examine

Thanks for the help


You probably could do this using graphical patch & variadic node with a buffer node, but you will need dummy pins to pass count & total to each level and the variadic pins would also be dummy pins. It would be a lot easier to implement in C++ using a FIFO queue (First In - First Out). A google search will give you lots of ways to implement the FIFO queue and references to standard C++ library implementation (which I would assume is available from XOD).

If you want to hard-code for a specific sample size, then you could create a patch with that number of cascading buffers to store the values. Note that the pulse needs to run backwards through the buffers to keep old values instead of filling all buffers with new value. Not sure what will happen to output of average while the buffers are updating, I’m guessing it will update as each buffer is updated unless you have a buffer on the output also.

Hmmm…the fact that buffer doesn’t have an output pulse makes it a bit harder to implement this…I assume you would have to use defer-pulse to connect the buffers…

This might do what you want for 3 samples:


Oops… Haven’t looked into the topic to check if someone replied already. Can’t add much to the @gweimer’s reply. In summary: you want to adjust some “inner” parameter, the variadic nodes mechanism as is will not help; I see no way currently to make an elegant solution with the adjustable buffer size. I came to the very similar solution as gweimer, but arranged the nodes in slightly another way. Here’s moving-average-4:


Ah…it never even accord to me to use defer-number instead of defer-pulse. That looks much cleaner, probably runs faster, and eliminates the need to buffer the output so it doesn’t change mid-update.

You will need to add a wire from PUSH to the last buffer-UPD if you want to use the above example…