Forums > Gen

RMS Averaging?


Jan 02 2017 | 5:47 pm

I’m looking for a gen~ alternative to average~ for rms averaging.

Anyone have a simple solution?

Thanks!

Jan 03 2017 | 6:24 am
// Gen RMS calculator.
// henszimmerman@gmail.com.

// Input buffer.
Delay input(8192, 1, feedback=0);

// Amount of samples to average.
Param n;

// Accumulator.
acc = 0;

// Step through all samples.
for(idx = 0; idx < n; idx += 1)
{
	// Read next value from input buffer.
	v = input.read(idx, 0, interp="spline");
	
	// Add square of value to accumulator.
	acc += (v * v);
}

// Store next value we read from the input.
input.write(in1);

// Output RMS of n samples.
out1 = sqrt(acc / n);
Jan 03 2017 | 8:09 am

Nice one!

Jan 03 2017 | 8:19 am

This is perfect, thanks HZ37!

Jan 03 2017 | 9:19 am

Hello , can u say , if i do at first sqrt(pow(in,2)) and after do averange – is that right ?

Jan 03 2017 | 11:38 am

Hello , can u say , if i do at first sqrt(pow(in,2)) and after do averange – is that right ?

no.

Jan 03 2017 | 11:42 am

// Gen RMS calculator.
// henszimmerman@gmail.com.

while this works correctly, it gets insanely expensive for larger averaging windows.
i would propose something like the code below.
caveat: averaging size is fixed, as i don’t know an easy way to reset a delay line in gen~.
you could make it work with a buffer, though.

Delay d(2000);
History y(0);
n = 2000;
rdiv = 1 / n;

sq = in1 * in1;
xn = d.read(n, interp="none");
avg = sq + y - xn;

out1 = sqrt(avg*rdiv);

y = avg;
d.write(sq);

Jan 03 2017 | 7:00 pm

for many applications you might want to/can downsample the analysis. in this particular situation the order rms->average can make sense.

Viewing 8 posts - 1 through 8 (of 8 total)

Forums > Gen