RMS Averaging?


    Jan 03 2017 | 1:47 am
    I'm looking for a gen~ alternative to average~ for rms averaging.
    Anyone have a simple solution?
    Thanks!

    • Jan 03 2017 | 2:24 pm
      // 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 | 4:09 pm
      Nice one!
    • Jan 03 2017 | 4:19 pm
      This is perfect, thanks HZ37!
    • Jan 03 2017 | 5:19 pm
      Hello , can u say , if i do at first sqrt(pow(in,2)) and after do averange - is that right ?
    • Jan 03 2017 | 7:38 pm
      Hello , can u say , if i do at first sqrt(pow(in,2)) and after do averange – is that right ?
      no.
    • Jan 03 2017 | 7:42 pm
      // 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 04 2017 | 3:00 am
      for many applications you might want to/can downsample the analysis. in this particular situation the order rms->average can make sense.
    • Jun 06 2017 | 6:11 pm
      Does HZ37's code provide RMS updated every sample, whereas Volker Böhm's code provides RMS value only every 2000 samples?
      A continous RMS, updated per sample, would be more desirable for example for a peak versus RMS comparison, threshold measurement and such.
      Thanx for any insight!