How to periodically sample a variable and then get an average value?

liik's picture

Hi,

How would one go about sampling a value (like from a random patch), every second or so, and then after a certain period of time get an average value from all the sampled values?

I'm not good in javascript, but my guess is to create a structure in javascript, and then sum up and divide the sum with the structure count…however how does one sample a value every second?

Thanx!

Achim Breidenbach's picture
Re: How to periodically sample a variable and then get an ...

Hi, this is the chain I would use:

  • "Wave Generator (LFO)" patch, with option Type "Square", outputting a value thats toggles from 1 to 0 in a certain time ("Periode")
  • This output goes into a "Pulse" patch that generates a single frame "1" each time the Wave Patch goes from 0 to 1
  • The Pulse Output you connect to the Filling input of a Queue-patch. Setup the "Queue Size" to fit the count of samples you want to average.
  • The "Value" input of that Queue patch will be sampled, so you connect the output "Value" of a "Random" patch to this input.

The output of the "Queue" patch is a structure of your values that you can feed in into a JavaScript patch to do the sum and division by the count of the structure.

Hope that helps!

Achim Breidenbach Boinx Software

liik's picture
Re: How to periodically sample a variable and then get an ...

Yes, that solved my problem, thanks!

Ivan

PreviewAttachmentSize
SamplingVariableValueIntoStructOverPeriod.qtz76.72 KB