On Wed, 29 Mar 2000, Lorick wrote: >From what you've described, most of what everyone's been suggesting is correct. I can a couple of things that you may wish to watch out for. The 'window' time, or the time over which you sample the signal, needs to be infinity for an RMS calculation. Obviously that condition can't be met. So be aware that sampling for a finite time can introduce errors. As an extreme example, let's consider your 300hz sinewave. This has a period of 1/300 or 3.33 mSec. If you sample for a quarter of the period, or 208 uSec, it's probably obvious that you'll introduce an error. However, if your sampling window is not even multiple of half of the period or (N * 1.6667mSec) you'll still introduce an error in the 'true' rms value. Compare the results for a window that is 1 cycle wide versus one that is 1 and a quarter cycles. There are two ways to minimize this error. If you know that you're signal is predominately 300Hz plus a "little noise", then you can sample for integer number of half periods of 300Hz. But if the frequency changes, then you need to adjust the sampling window. Yuk. Second, you can make the window as "long as possible" and then combine the results of successive RMS calculations. For example, if you sampled about 5 cycles (but not exactly 5) you'll get a small error (smaller than if you sampled over about 1 cycle). Now if you average two consecutive runs through the RMS algorithm you'll get a better result. But, you'll still have an error. However, you can concatenate the consecutive calculations before performing the square root. This will, over time, converge to a more accurate result. Also, the hard coded DC value of 128 should, as others have suggested, be subtracted from your data stream prior to squaring. There are two observations here. As (I believe it waw Russel) suggested, you may improve on the estimation of the DC component by explicitly measuring it. This estimate may be improved in analogous manner to above by combining results of several passes through the algorithm. Second, if the DC term is really just '128', then the 8-bit squaring operation can be turned into a 7-bit one and computed in 31 cycles. There are a few more suggestions I have, but I don't have the time now to elaborate... Scott