RMS = Root Mean Squared. It is mathematically identical to the standard deviation. To compute it: As you collect n samples (x's), accumulate the sum of the x's (sum_of_x) and the sum of x^2's (sum_of_x_squared). After you have finished collecting those n samples, stdev = sqrt(sum_of_x_squared/n - (sum_of_x/n)^2) BTW, the term sum_of_x/n is the mean or DC offset of the signal. ---------------- Note that for computing RMS, there is no need to store all n samples. Once they have gone into the sums, you are done with them. The square is probably best computed with a table lookup. For 10 bit signed samples, it takes 512 table entries, since x^2 = (-x)^2, and is always positive. The sums can grow quite quickly. If you collect 1024 samples, then the sum will be 10 bits bigger than the individual samples. The square of a 10-bit signed number is 18 bits, so the sum of 1024 of them will be 28 bits. Your sampling period needs to be longer than the lowest-frequency component, and the sampling rate needs to be high enough to meet the Nyquist criteria for the highest-frequency component. If your AC signal is capacitively coupled so that you can be certain that the DC offset is zero, then you can save some bits in the sums. Microchip's floating-point library works quite well, and converting those integer sums you have collected into floating-point will considerably reduce the pain of the final computations, as well as whatever scaling you need to do to get the results into meaningful units. On a 20-MHz 16F876, I measured over 1K floating-point ops per second. > -----Original Message----- > From: Edson Brusque [mailto:ebrusque@TERRA.COM.BR] > Sent: Wednesday, July 25, 2001 6:45 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: [EE]: RMS again (ouch!) > > > Hello, > > I'm making an RMS voltage measurement with the PIC at one of my > circuits. > > Now, how can I get a precise result if I don't know the > frequency and > format of the waveform going to the PIC A/D? > > I mean, if the wave is very clean, like a pure > sinusoidal, I could try > to sample it between two zero-crossings and I will have a very precise > value. But what about if it does have some loud harmonics? > For example, if > it's a sine with 100Hz plus a sine with 187Hz, both mixed and > with the same > intensity, the zero-crossings will be all over the place so I > can't sample > between two zero-crossing because the values will be meaningless. > > Any ideas? > > Thanks, > > Brusque > > ----------------------------------- > Edson Brusque > Research and Development > C.I.Tronics Lighting Designers Ltda > (47) 323-2138 / (47) 9993-6453 > Blumenau - SC - Brazil > www.citronics.com.br > ----------------------------------- > > -- > http://www.piclist.com hint: To leave the PICList > mailto:piclist-unsubscribe-request@mitvma.mit.edu > > -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu