On Jul 9, 2007, at 1:13 PM, Luigi Castelli wrote: Hi there,
I am working on a true RMS detector and, even though it seems like an easy task to accomplish, I stumbled upon a problem I don't know how to solve.
I know the math for true RMS value detection is:
RMS(x) = sqrt( 1/N * 0 to N (x[n] * x[n]) )
NIT: the index should vary from 0 to N-1, not from 0 to N.
To implement the function efficiently I am not using a moving average window like the formula would indicate, but I am rather using a 1-pole lowpass filter to perform the averaging.
--- I am not an expert, but it looks like your filter applies a DIFFERENT coefficient depending on whether the instantaneous sample value is ABOVE or BELOW the current "average". That is guaranteed to distort the signal.
I believe the "clamp" and "relax" timers should be applied AFTER the true RMS is computed, you can't do it this way.
If you're looking to speed things up, consider doing a moving average, but don't start from scratch every time.
If your block size is 100, then add up samples 0-99 and call it the total. When sample #100 comes in, figure total = total - Sample #0 + sample #100, then divide by 100. When sample #101 comes in, figure total = total - Sample #1 + sample #101, then divide by 100. When sample #102 comes in, figure total = total - Sample #2 + sample #102, then divide by 100. ... and so on.
HTH
---------------------------------------------------------------- Steve Bird Culverson Software - Elegant software that is a pleasure to use.
|