DSPRelated.com
Forums

True RMS and averaging.

Started by martind August 12, 2009
Hi All,

I am a newbie to DSP, and near the bottom of the learning curve. I am
currently designing a 3-phase IDMT protection relay, which monitors
voltage, current, earth leakage etc.

The question I have is related to the monitoring of the current. I am
sampling 3-phases of current and need to convert each phase to True RMS,
and in it's simplest form, output a signal when the any phases true RMS
current reaches either a predefined trip point, or IDMT output level.

I am using 32-bit fixed point hardware, with MAC.

My confusion is the True RMS conversion itself. One way is to take 1 cycle
of samples, square each sample as received, then divide by total number of
samples then sqrt. But this has a disadvantage as the result if the
calculation is given at the end of the cycle. And the response time would
not meet the spec.

Another way would be to keep a circular buffer, that way each sample would
be square rooted, and be available on each sample. However, sqrt on each
sample would take up too much CPU. 

So, reading around it is advised to only square root when needed. So I am
thinking of not square rooting at all, but squaring the result I need to
compare it with, staying in the square domain. 

Then that (should) just leave me with implementation of an average
algorithm for fixed point DSP. 

I have read that a 1-pole IIR should produce the result I need (or be
accurate enough) to represent True RMS (DC equivalent or the heat rise of a
conductor).

Does anyone have any thoughts/advice/experience in this area? Any advice
appreciated.


Thanks,



Martin.


martind wrote:
> Hi All, > > I am a newbie to DSP, and near the bottom of the learning curve. I am > currently designing a 3-phase IDMT protection relay, which monitors > voltage, current, earth leakage etc. > > The question I have is related to the monitoring of the current. I am > sampling 3-phases of current and need to convert each phase to True RMS, > and in it's simplest form, output a signal when the any phases true RMS > current reaches either a predefined trip point, or IDMT output level. > > I am using 32-bit fixed point hardware, with MAC. > > My confusion is the True RMS conversion itself. One way is to take 1 cycle > of samples, square each sample as received, then divide by total number of > samples then sqrt. But this has a disadvantage as the result if the > calculation is given at the end of the cycle. And the response time would > not meet the spec. > > Another way would be to keep a circular buffer, that way each sample would > be square rooted, and be available on each sample. However, sqrt on each > sample would take up too much CPU. > > So, reading around it is advised to only square root when needed. So I am > thinking of not square rooting at all, but squaring the result I need to > compare it with, staying in the square domain. >
If all you want is to compare to a static level (or levels) then taking the square root is a waste of time. So, you're on the right track there. I don't know what a circular buffer has to do with computing squares or square roots ....... a buffer is a memory configuration .. no operations implied there! You omitted after square each sample to *sum the results* then divide by the total number of samples. Fred
>
martind <martind574@googlemail.com> wrote:
 
< I am a newbie to DSP, and near the bottom of the learning curve. I am
< currently designing a 3-phase IDMT protection relay, which monitors
< voltage, current, earth leakage etc.
 
< The question I have is related to the monitoring of the current. I am
< sampling 3-phases of current and need to convert each phase to True RMS,
< and in it's simplest form, output a signal when the any phases true RMS
< current reaches either a predefined trip point, or IDMT output level.

Note that RMS implies time averaging...
 
< I am using 32-bit fixed point hardware, with MAC.
 
< My confusion is the True RMS conversion itself. One way is to take 1 cycle
< of samples, square each sample as received, then divide by total number of
< samples then sqrt. But this has a disadvantage as the result if the
< calculation is given at the end of the cycle. And the response time would
< not meet the spec.

What is the spec?  

(big snip)

As you mentioned (I believe snipped) fastest is to compare against
the square, instead of taking the square root.

My thought is that you want a decaying average (statisitical term),
which gives you an average at any time, weighting the more recent
data higher.  That should correspond to the resulting temperature
rise due to I**2*R heating, with the appropriate time constant.

I believe that corresponds to your one pole IIR filter.

-- glen

 
martind wrote:
> Hi All, > > I am a newbie to DSP, and near the bottom of the learning curve. I am > currently designing a 3-phase IDMT protection relay, which monitors > voltage, current, earth leakage etc. > > The question I have is related to the monitoring of the current. I am > sampling 3-phases of current and need to convert each phase to True RMS, > and in it's simplest form, output a signal when the any phases true RMS > current reaches either a predefined trip point, or IDMT output level. > > I am using 32-bit fixed point hardware, with MAC. > > My confusion is the True RMS conversion itself. One way is to take 1 cycle > of samples, square each sample as received, then divide by total number of > samples then sqrt. But this has a disadvantage as the result if the > calculation is given at the end of the cycle. And the response time would > not meet the spec. > > Another way would be to keep a circular buffer, that way each sample would > be square rooted, and be available on each sample. However, sqrt on each > sample would take up too much CPU.
It also wouldn't work RMS is the square root of the sum of the squares, not the squared sum of the square roots.
> So, reading around it is advised to only square root when needed. So I am > thinking of not square rooting at all, but squaring the result I need to > compare it with, staying in the square domain.
That works.
> Then that (should) just leave me with implementation of an average > algorithm for fixed point DSP.
Average involves division. Instead, multiply the limit compared against. That needs to be done only once, when the limit is decided upon.
> I have read that a 1-pole IIR should produce the result I need (or be > accurate enough) to represent True RMS (DC equivalent or the heat rise of a > conductor).
A circular buffer that implements a boxcar averager of squares on one cycle will be better.
> Does anyone have any thoughts/advice/experience in this area? Any advice > appreciated.
You wrote, "I am a newbie to DSP." Better would have been, "I am a newbie." Keep plugging. You'll get there. :-) Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
glen herrmannsfeldt wrote:
> martind <martind574@googlemail.com> wrote: > > < I am a newbie to DSP, and near the bottom of the learning curve. I am > < currently designing a 3-phase IDMT protection relay, which monitors > < voltage, current, earth leakage etc. > > < The question I have is related to the monitoring of the current. I am > < sampling 3-phases of current and need to convert each phase to True RMS, > < and in it's simplest form, output a signal when the any phases true RMS > < current reaches either a predefined trip point, or IDMT output level. > > Note that RMS implies time averaging... > > < I am using 32-bit fixed point hardware, with MAC. > > < My confusion is the True RMS conversion itself. One way is to take 1 cycle > < of samples, square each sample as received, then divide by total number of > < samples then sqrt. But this has a disadvantage as the result if the > < calculation is given at the end of the cycle. And the response time would > < not meet the spec. > > What is the spec? > > (big snip) > > As you mentioned (I believe snipped) fastest is to compare against > the square, instead of taking the square root. > > My thought is that you want a decaying average (statisitical term), > which gives you an average at any time, weighting the more recent > data higher. That should correspond to the resulting temperature > rise due to I**2*R heating, with the appropriate time constant. > > I believe that corresponds to your one pole IIR filter.
You need to get the decrement just right with an exponential averager, and even then it's only approximate. By squaring each reading, adding it to the sum of squares, stuffing it into the circular buffer, and subtracting what comes out the end from the sum of squares, there is an exact result at all times. The cost is one squaring, one add, one subtract, one store, one read, and two pointer updates for each phase. That is probably acceptable. (Don't try this with floating point. Fixed-point arithmetic makes the boxcar from winding up.) Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Jerry Avins <jya@ieee.org> wrote:
(snip)
 
> You need to get the decrement just right with an exponential averager, > and even then it's only approximate. By squaring each reading, adding it > to the sum of squares, stuffing it into the circular buffer, and > subtracting what comes out the end from the sum of squares, there is an > exact result at all times. The cost is one squaring, one add, one > subtract, one store, one read, and two pointer updates for each phase. > That is probably acceptable. (Don't try this with floating point. > Fixed-point arithmetic makes the boxcar from winding up.)
But how do you know how long to make it? Well, I suppose with the decaying average you also need a constant. If you know the period, then yes you can do that and average over one period. If you don't know the period, as most True RMS DVM's don't, then what do you do? -- glen
>Jerry Avins <jya@ieee.org> wrote: >(snip) > >> You need to get the decrement just right with an exponential averager,
>> and even then it's only approximate. By squaring each reading, adding
it
>> to the sum of squares, stuffing it into the circular buffer, and >> subtracting what comes out the end from the sum of squares, there is an
>> exact result at all times. The cost is one squaring, one add, one >> subtract, one store, one read, and two pointer updates for each phase.
>> That is probably acceptable. (Don't try this with floating point. >> Fixed-point arithmetic makes the boxcar from winding up.) > >But how do you know how long to make it? > >Well, I suppose with the decaying average you also need a constant. > >If you know the period, then yes you can do that and average over >one period. If you don't know the period, as most True RMS DVM's >don't, then what do you do? >
Fred, Glen, Jerry, thanks for your help and taking the time to reply. The response time in the spec is 10ms. I assumed that the period I would be taking the samples over would be 1 full mains voltage cycle, spec'd between 45Hz to 65Hz. For instance at 50Hz, 20ms period. Sample rate I haven't decided upon yet, important factor which will determine frequency response but I guess it's what I can achieve with the processor. (12-channels to sample in all). Jerry I am kind of swayed now into using the circular buffer, given the accuracy. Have plenty of memory to store the samples. I used Scilab to model an IIR vs averaging, and got similar responses, but not quite the same. But Glen I agree, how many samples to you take? I did read that 2 cycles of the mains would be better than 1. But obviously less responsive. I've seen some systems sync the current measurement with the voltage. So on a -VE to +VE transition, but I can't see the point as it's just RMS current were are interested in. Anyway, thanks a lot. *Newbie* Martin.
>-- glen >
glen herrmannsfeldt wrote:
> Jerry Avins <jya@ieee.org> wrote: > (snip) > >> You need to get the decrement just right with an exponential averager, >> and even then it's only approximate. By squaring each reading, adding it >> to the sum of squares, stuffing it into the circular buffer, and >> subtracting what comes out the end from the sum of squares, there is an >> exact result at all times. The cost is one squaring, one add, one >> subtract, one store, one read, and two pointer updates for each phase. >> That is probably acceptable. (Don't try this with floating point. >> Fixed-point arithmetic makes the boxcar from winding up.) > > But how do you know how long to make it?
Make it as precisely one power cycle as the sample rate allows.
> Well, I suppose with the decaying average you also need a constant.
A decaying average carries along a lot of history. If even one-cycle latency is too long, you need a number that reflects the present as closely as possibly. The one-cycle boxcar averager always shows the RMS of the last full cycle, starting one cycle ago, with at most one sample of delay.
> If you know the period, then yes you can do that and average over > one period. If you don't know the period, as most True RMS DVM's > don't, then what do you do?
This isn't any old true-RMS meter. It's a three-phase power-line relay. For power lines, you always know the period. (If you don't, the grid has already fallen apart.) A relay (that's what they call a circuit breaker's controller) needs to trip in no more than a cycle on severe overload and faster on a dead fault. The tail of an IIR averager isn't helpful. Electro-mechanical relays often measure a single aspect. Modern digital power relays usually measure many, including phase voltages, power, negative-sequence currents, power factor, and more. Once the current transformers and voltage taps are digitized, the rest is software, so why not? Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
On Thu, 13 Aug 2009 11:52:05 -0400, Jerry Avins <jya@ieee.org> wrote:

>glen herrmannsfeldt wrote: >> Jerry Avins <jya@ieee.org> wrote: >> (snip) >> >>> You need to get the decrement just right with an exponential averager, >>> and even then it's only approximate. By squaring each reading, adding it >>> to the sum of squares, stuffing it into the circular buffer, and >>> subtracting what comes out the end from the sum of squares, there is an >>> exact result at all times. The cost is one squaring, one add, one >>> subtract, one store, one read, and two pointer updates for each phase. >>> That is probably acceptable. (Don't try this with floating point. >>> Fixed-point arithmetic makes the boxcar from winding up.) >> >> But how do you know how long to make it? > >Make it as precisely one power cycle as the sample rate allows. > >> Well, I suppose with the decaying average you also need a constant. > >A decaying average carries along a lot of history. If even one-cycle >latency is too long, you need a number that reflects the present as >closely as possibly. The one-cycle boxcar averager always shows the RMS >of the last full cycle, starting one cycle ago, with at most one sample >of delay. > >> If you know the period, then yes you can do that and average over >> one period. If you don't know the period, as most True RMS DVM's >> don't, then what do you do? > >This isn't any old true-RMS meter. It's a three-phase power-line relay. >For power lines, you always know the period. (If you don't, the grid has >already fallen apart.) A relay (that's what they call a circuit >breaker's controller) needs to trip in no more than a cycle on severe >overload and faster on a dead fault. The tail of an IIR averager isn't >helpful. > >Electro-mechanical relays often measure a single aspect. Modern digital >power relays usually measure many, including phase voltages, power, >negative-sequence currents, power factor, and more. Once the current >transformers and voltage taps are digitized, the rest is software, so >why not?
If it's a power line, and you know the period, wouldn't you know the phase as well? I wonder if you could continuously sample, and make a comparison of each sample to the appropriate level of current at that point in the cycle, rather than an average RMS value. Then if n sequential samples exceed their appropriate thresholds, trip. -- John
glen herrmannsfeldt  <gah@ugcs.caltech.edu> wrote:

>If you know the period, then yes you can do that and average over >one period. If you don't know the period, as most True RMS DVM's >don't, then what do you do?
Something like a Hamming window can remove some (perhaps, most) of the bias that comes from periodicity. It may not have the fast response the OP needs however. Steve