One cycle 50/60Hz RMS Calculation

My question is based on this paper:

formatting link

They claim to calculate RMS with non-integer number of samples to improve a ccuracy over half cycle or one cycle RMS.

In my case for one cycle I can't have an integer N that matches both 50 and 60 Hz and possible fluctuations. In the microcontroller, the plan I have i s to set an ADC triggered by a timer for a fixed sampling frequency, say 6 kHz.. I can also use DMA or double buffer approach if needed.

What do you think of the approach of the paper? I'm open to other suggestio ns regarding the proper way to sample the signal for a one cycle RMS. I kno w that if I increase the number of cycles I can find an integer sample time period that matches both 50/60 Hz, but the point is that I need RMS per on e cycle. Does not need to be so precise, even integer RMS is Ok.

Some caveat:

  1. In the hardware, the signal is shifted with a DC value to match the ADC positive values. For example, my ADC reads 0-3.3V, then the signal swings a round 3.3/2. This DC value is pretty stable so averaging it and subtract fr om the reading works.
Reply to
Gold_Spark
Loading thread data ...

Seems to me that if you want the RMS value per cycle, you have to know what a cycle is.

Given a sine-squared curve, you only need two samples spaced by half the period. But you need to know the period.

Since the world is noisy, more samples per period is better than two. But again, they need to be spaced right.

Sampling at 6 KHz, you could find the positive zero crossings of the sine wave and average all the sin^2 samples between them. That's not hard.

--

John Larkin         Highland Technology, Inc 

Science teaches us to doubt. 

  Claude Bernard
Reply to
jlarkin

accuracy over half cycle or one cycle RMS.

nd 60 Hz and possible fluctuations. In the microcontroller, the plan I have is to set an ADC triggered by a timer for a fixed sampling frequency, say

6 kHz.. I can also use DMA or double buffer approach if needed.

Mathematically, if you can delay the wave by 90 degrees, then the sum of th e signal-squared and the delayed-signal-squared ought to be a constant value for a sinewave inpu t. It wouldn't matter about the zero-crossing times being on, or off, the frequency. So, I''d p hase-lock to the waveform, and take samples into a buffer with at least a quarter-wave worth of stored values, and instead of summing over a real half-wave, you can pick anything from a quarter wave up to a whole wave, and make any kind of average that suits your fancy.

A digital PLL is relatively trivial at 50 or 60 Hz. Depending on the dynam ics of 'fluctuations', of course.

Reply to
whit3rd

The approach in the paper seems like it's for very cost-constrained systems.

The stock Arduino/AVR 8-bit uP environment's sampling rate is 10kHz but that can be boosted to 100s of kHz in software, and if it all it needs to do most of the time is calculate RMS values of 50/60Hz sines, an 8 bit RISC at 20 MHz is perfectly capable of that. though I'd use one with a hardware multiplier, the really cheap ones don't have it, in which case see above paper for "cost constrained."

Or buy one of those mystery-meat 32 bit ARMs from China for 25 cent and hope you can figure out the documentation.

Reply to
bitrex

accuracy over half cycle or one cycle RMS.

nd 60 Hz and possible fluctuations. In the microcontroller, the plan I have is to set an ADC triggered by a timer for a fixed sampling frequency, say

6 kHz.. I can also use DMA or double buffer approach if needed.

ions regarding the proper way to sample the signal for a one cycle RMS. I k now that if I increase the number of cycles I can find an integer sample ti me period that matches both 50/60 Hz, but the point is that I need RMS per one cycle. Does not need to be so precise, even integer RMS is Ok.

C positive values. For example, my ADC reads 0-3.3V, then the signal swings around 3.3/2. This DC value is pretty stable so averaging it and subtract from the reading works.

I only perused the paper, but it seems that they mentioned "variable freque ncy". It seems to me that getting 128 samples to do an RMS calculation is way more than enough. The problem is the variable frequency part. I would use my samples to estimate the zero crossing-s and then built an algorithm around the samples I have in between the zero crossings I measured.

Reply to
blocher

If it's a good sine wave, it's not hard to seperate out single cycles by looking at zero crossings, with a little filtering maybe.

Current waveforms can be very ugly. Best to use zero crossings of the AC voltage waveform (which could be seen on one port bit) to locate the cycles, and use the ADC data for current.

--

John Larkin         Highland Technology, Inc 

Science teaches us to doubt. 

  Claude Bernard
Reply to
jlarkin

Point of the paper is about doing the detection _fast_. 128 samples is plenty _if_ the sampling period is aligned with the frequency of the sine.

If it isn't and you have _only_ 128 samples of arbitrary phase with respect to the sine period to work with, you can't naively estimate the zero crossings without error any more than you can naively calculate the RMS and get the right answer, the true zero-crossings will fall in-between sampling periods, the data simply doesn't exist so you either need to wait for more samples (which you don't wanna do) or have to interpolate as per the paper.

Reply to
bitrex

You only need two samples per cycle of an ideal sine wave that extends to infinity in both directions to tell you everything you want to know about it in principle, but what is the bandwidth of a signal which is a hacked single cycle of a 60 Hz sine that is then zero out to infinity on the left and right. It ain't 60 Hz!

Reply to
bitrex

The OP says he doesn't need extreme accuracy but wants one RMS value per cycle. The AC line voltage is noisy anyhow, and current waveforms can be horrors, so the very concept of single-cycle accuracy is silly.

128 samples per cycle is plenty, if you can find where the cycles are.

I'd lowpass filter the voltage waveform and run through a comparator to a port bit. Look at that to see where the cycles are. Process all the ADC samples, for voltage or current, in each cycle.

--

John Larkin         Highland Technology, Inc 

Science teaches us to doubt. 

  Claude Bernard
Reply to
jlarkin

Good luck doing all that in one cycle.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC / Hobbs ElectroOptics 
Optics, Electro-optics, Photonics, Analog Electronics 
Briarcliff Manor NY 10510 

http://electrooptical.net 
http://hobbs-eo.com
Reply to
Phil Hobbs

rove accuracy over half cycle or one cycle RMS.

50 and 60 Hz and possible fluctuations. In the microcontroller, the plan I have is to set an ADC triggered by a timer for a fixed sampling frequency, say 6 kHz.. I can also use DMA or double buffer approach if needed.

gestions regarding the proper way to sample the signal for a one cycle RMS. I know that if I increase the number of cycles I can find an integer sampl e time period that matches both 50/60 Hz, but the point is that I need RMS per one cycle. Does not need to be so precise, even integer RMS is Ok.

e ADC positive values. For example, my ADC reads 0-3.3V, then the signal sw ings around 3.3/2. This DC value is pretty stable so averaging it and subtr act from the reading works.

requency". It seems to me that getting 128 samples to do an RMS calculatio n is way more than enough. The problem is the variable frequency part. I would use my samples to estimate the zero crossing-s and then built an algo rithm around the samples I have in between the zero crossings I measured.

e.

If he is sampling the input there is no reason to do any special filtering in the analog domain other than anti-alias filtering. The method described above using squared samples phase shifted and summed should provide a simp le, effective way to make the measurement. If not that, filtering in the d igital domain will be quite effective.

--

  Rick C. 

  - Get 1,000 miles of free Supercharging 
  - Tesla referral code - https://ts.la/richard11209
Reply to
Ricketty C

Assuming true sine wave:

Why not use a random noise generator to sample the waveform over several cycles, which would not need any pll, just a sample / hold and sum ?...

Reply to
Chris

I think using a comparator to fire an interrupt and bring the ADC up on the zero-cross detect works fine if you only need to check intermittently, the ADC will come up in 10s of uS a lot shorter than the sampling period.

But if I understand the paper correctly you can use its method on a per-sample basis and still do a running average, reducing overhead; if you're on a relatively resourced-constrained processor like an 8-bitter having to do an interrupt every 50 or 60 seconds and then calculate the naive average within the cycle period is going to strain its resources.

Reply to
bitrex

The OP wanted RMS readings for each individual (half)cycle, which makes sense e.g. with protection relays.

However, if the electricity is provided by a real mechanical generator the short term (1 s) stability is quite good thanks to the large inertia of the generator rotor (often tons). The DPLL should be able to track the mains frequency quite accurately and calculate the mains cycle period and then use all the samples between (half)cycle marks for RMS calculations.

Reply to
upsidedown

improve accuracy over half cycle or one cycle RMS.

One can imagine scenarios where it would be reasonable, sure. But the OP hasn't told us much about the actual one.

Or it could be a solid-state inverter, or a gas-powered 500W genny with an iffy ignition. Or he might not know--it seems to be mostly a theoretical question.

If everything is guaranteed to be slowly-varying and otherwise well-behaved, all is easy, sure. But that's not the interesting case--even whit's airy dismissal gave a nod to 'depending on the dynamics'.

Cheers

Phil Hobbs

--
Dr Philip C D Hobbs 
Principal Consultant 
ElectroOptical Innovations LLC / Hobbs ElectroOptics 
Optics, Electro-optics, Photonics, Analog Electronics 
Briarcliff Manor NY 10510 

http://electrooptical.net 
http://hobbs-eo.com
Reply to
Phil Hobbs

Why not have it detect whether it is facing 50Hz or 60Hz mains supply and then act accordingly to choose the right length N. Sampled at 6kHz there is always an integer number of samples in a nominal mains cycle.

If you are doing it cycle by cycle there will be a fractional sample error in one of them but it shouldn't matter much provided you make some attempt at starting and ending on a lowish zero crossing value.

Mains power doesn't drift very far away from its nominal frequency unless something is horribly wrong.

Using a common period like 100ms which is an exact multiple of cycles for both frequencies is one good way out. Most precision ADCs intended to work both in the US and ROW use this strategy. Japan has always done it since half their country is on US 60Hz 100vac and the other UK 50Hz.

--
Regards, 
Martin Brown
Reply to
Martin Brown

accuracy over half cycle or one cycle RMS.

nd 60 Hz and possible fluctuations. In the microcontroller, the plan I have is to set an ADC triggered by a timer for a fixed sampling frequency, say

6 kHz.. I can also use DMA or double buffer approach if needed.

ions regarding the proper way to sample the signal for a one cycle RMS. I k now that if I increase the number of cycles I can find an integer sample ti me period that matches both 50/60 Hz, but the point is that I need RMS per one cycle. Does not need to be so precise, even integer RMS is Ok.

C positive values. For example, my ADC reads 0-3.3V, then the signal swings around 3.3/2. This DC value is pretty stable so averaging it and subtract from the reading works.

I didn't provide much details, but basically my application is to detect le akage currents (earth) in the order of mAs, that's why I wanted fast detect ion. I've seen some methods that use peak detection. It is right that peak detection offers the quickest response, but not necessarily a reliable one. I don't know how distorted my current waveforms are, but I certainly would not want to assume they are perfect sine waves in which peak values may no t be easy to find. Maybe an average point by point could help get better p eak approximation. At the end, that is why I thought of finding RMS per cyc le since it could yield a more reliable result.

Reply to
Gold_Spark

ve accuracy over half cycle or one cycle RMS.

and 60 Hz and possible fluctuations. In the microcontroller, the plan I ha ve is to set an ADC triggered by a timer for a fixed sampling frequency, sa y 6 kHz.. I can also use DMA or double buffer approach if needed.

stions regarding the proper way to sample the signal for a one cycle RMS. I know that if I increase the number of cycles I can find an integer sample time period that matches both 50/60 Hz, but the point is that I need RMS pe r one cycle. Does not need to be so precise, even integer RMS is Ok.

ADC positive values. For example, my ADC reads 0-3.3V, then the signal swin gs around 3.3/2. This DC value is pretty stable so averaging it and subtrac t from the reading works.

leakage currents (earth) in the order of mAs, that's why I wanted fast dete ction. I've seen some methods that use peak detection. It is right that pea k detection offers the quickest response, but not necessarily a reliable on e. I don't know how distorted my current waveforms are, but I certainly wou ld not want to assume they are perfect sine waves in which peak values may not be easy to find. Maybe an average point by point could help get better peak approximation. At the end, that is why I thought of finding RMS per c ycle since it could yield a more reliable result.

How about something like a GFI circuit? This is an alright discussion of how they work.

formatting link

George H.

Reply to
George Herold

I can't think of one right now. Seems like one could square the samples, lowpass filter, optional square root, trip on some limit. Quantifying thermal protection to whole cycles sounds worse to me.

--

John Larkin         Highland Technology, Inc 

Science teaches us to doubt. 

  Claude Bernard
Reply to
jlarkin

I understood that there would be an ADC running at 6 KHz. That's a reasonable interrupt rate if indeed he wants to use interrupts. Looking at the comparator port bit within the interrupt is easy.

Interrupts are way too popular. Some people think everything should interrupt.

I do have one product with 12 isolated acquisition and control channels, each with a dinky ARM processor, each doing its thing in an IRQ at 200 KHz. We cranked down the CPU clock rates to save power. Each does compute RMS and runs some filters and a PID loop.

--

John Larkin         Highland Technology, Inc 

Science teaches us to doubt. 

  Claude Bernard
Reply to
jlarkin

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.