Searching \ for '[EE]: RMS again (ouch!)' in subject line. ()
Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=rms+again+ouch
Search entire site for: 'RMS again (ouch!)'.

Exact match. Not showing close matches.
'[EE]: RMS again (ouch!)'
2001\07\25@194815 by

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
http://www.citronics.com.br
-----------------------------------

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

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 removed}
Hello Don,

My circuit have to measure voltage at the output of a transformer. The
input of the transformer is wired to the output of a (mains) power
generator. The power generator can be very bed, with lot of noises,
frequency flutuations and so on. In this situation, a perfect power
generator would give a perfect sine at 60Hz but this simply isn't true in
this case.

The output of the transformer goes to a voltage divider (two resistors)
and to a full-wave precision rectifier with an op-amp. So, I don't need to
calculate the DC offset and my reading will always be positive.

The PIC ADC will "see" something like this (sorry for the ugly
graphics):

|
|    **         **         **
|   *  *       *  *       *  *
|  *    *     *    *     *    *     *
| *      *   *      *   *      *   *
|*        * *        * *        * *
+----------*----------*----------*---

If I sample between zero crossings like:

|
|    **         **         **
|   *  *       *  *       *  *
|  *    *     *    *     *    *     *
| *      *   *      *   *      *   *
|*        * *        * *        * *
+----------*----------*----------*---
^---------------------^

I will have a very precise reading. Now, what about if I sample during
this time:

|
|    **         **         **
|   *  *       *  *       *  *
|  *    *     *    *     *    *     *
| *      *   *      *   *      *   *
|*        * *        * *        * *
+----------*----------*----------*---
^-----------------^

The result wouldn't be meaningless?

Best regards,

Brusque

-----------------------------------
Edson Brusque
Research and Development
C.I.Tronics Lighting Designers Ltda
(47) 323-2138  /  (47) 9993-6453
Blumenau  -  SC  -  Brazil
http://www.citronics.com.br
-----------------------------------

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestmitvma.mit.edu

On Wed, 25 Jul 2001, Edson Brusque wrote:

>
>     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.
>
If you know the frequency range of your signals then a second order
If your signals have very close frequency than maybe a notch filter will
help you more. I'm curious too if this problem could be done just in
software and how ?
Vasile

--

In message <005e01c11564\$2d6214c0\$0556b0c8@brusque>, Edson Brusque
<ebrusqueTERRA.COM.BR> writes
>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?

You can buy chips that do this in hardware, from what I can remember
they are some kind of multiplier?.
--

Nigel.

/--------------------------------------------------------------\
| Nigel Goodwin   | Internet : nigelglpilsley.co.uk           |
| Lower Pilsley   | Web Page : http://www.lpilsley.co.uk       |
| Chesterfield    | Official site for Shin Ki and New Spirit   |
| England         |                 Ju Jitsu                   |
\--------------------------------------------------------------/

--

Brusque,

I would run the signal through an op amp configured as differential
amplifier as the CMR (common mode rejection) characteristics of the
differential amplifier will attenuate noise and any signal common to both
inputs of the op amp. As for signal harmonics, it's not possible that the
harmonic of a signal would be at the same amplitude as the primary signal.
Following the differential amplifier with a PLL (phase locked loop) will
assure a fix on the primary signal and a rejection of the secondary
harmonics. The frequency of the primary signal can shift and the PLL will
follow. If two primary signals are present of similar amplitudes, then the
PLL will lock onto the perceived strongest signal.
Good luck.

Sincerely,
Ned Seith
Nedtronics
59 3rd Street
Gilroy, CA 95020
(408) 842-0858
G O T    G A R L I C ?
GILROY GARLIC FESTIVAL 2001 !
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

At 08:44 PM 7/25/01 -0300, you wrote:
{Quote hidden}

--

RMS has nothing to do with zero crossings, it has to do with time. Just
measure, square, and add the voltages for a second, then sqrt and divvy by
the number of samples. Neither the start nor the end have anything to do
with zero crossings.

You can make a cuontinuous-reading RMS meter using the stream of read data
back to 1 second - 1 sample time. With each new sample you get another
'second' to compute RMS from. You can water this down to as slow as you
wish. For human-read meters >2Hz update is too fast afaik.

Peter

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...