Let's say I need to sample 50/60 Hz signals to find RMS. I can use for example 1kHz sampling frequency. That means 100ms sampling is 5 cycles of 50Hz and 6 cycles for 60 Hz. That's coherent sampling. But does this account for frequency variations? I don't have zero cross detection in hardware, maybe if I do it in software (microcontroller) it may help. I've heard that windowing the signal help reduce discontinuities in case I don't exactly get a integer multiple of the frequencies during sampling. Should I use windowing? What other approaches can be implemented?

  • $\begingroup$ Do you need true RMS value, or can you assume something about the waveform? E.g. if it is a pure sine wave then you can find the peak value and divide by sqrt(2). $\endgroup$
    – Justme
    Oct 14, 2020 at 16:38
  • $\begingroup$ Unfortunately I can't assume it is pure sine, so I don't rely much on the peak $\endgroup$ Oct 14, 2020 at 17:30

2 Answers 2


That's coherent sampling.

Assuming this is a AC power application: it's only coherent sampling if you derive the sampling clock directly from the AC frequency using a PLL (Phase Locked Loop) or equivalent.

But does this account for frequency variations?

Depends on how you derive the sampling clock. If you use a PLL it will track the AC frequency, if you use an independent clock, the frequency will indeed drift.

Should I use windowing? What other approaches can be implemented?

If you really just want to measure the RMS of the signal, you don't need coherent sampling. Actually incoherent is better. You just need to make sure you have enough samples.

  • $\begingroup$ Yes, I only want RMS. I was thinking if I needed strictly a integer number of samples for both 50/60Hz but sometimes that is hard to get when I want only 1-2 cycle fast RMS $\endgroup$ Oct 14, 2020 at 13:31

Assuming $\frac{f_s}{f} \neq N$ where N is an integer.

There are 2 easy ways that I can see to compute the RMS value

1st method :

You could try to accumulate several periods of data. For example with fs = 1 kHz, f = 61 Hz, you could compute the RMS of 82 points which gives about 5.002 signal periods. The error introduced by the non-integer number of periods will be really small.

Pro : This method is really simple

Con : The latency to compute the RMS is variable depending on the frequency. Furthermore, if the frequency varies quickly the RMS estimate will also be less accurate.

2nd method

You can adjust the RMS calculation for fractional samples. This method is better if you cannot tolerate latency as you don't need to wait multiple periods to estimate the RMS.

Basically, assuming f = 61 Hz et Fs = 1 kHz.

P = 16.393 samples. You have 16 whole samples, N = 16 and 0.393 fractional samples. $\delta$= 0.393

$$X_{RMS} = \sqrt{\frac{1}{P}\left(\sum_{n=1}^N x_n^2 + \delta\left(\frac{1-\delta}{2}x_N + \frac{1+\delta}{2} x_{N+1}\right)^2\right)}$$

Source for this algorithm : http://www.eletrica.ufpr.br/edu/artigos/CIL22-012_final_gerson.pdf

  • $\begingroup$ I may need something like this since I'd like to find 1 cycle RMS and there's not an integer for both 50/60Hz and could be potential frequency variation $\endgroup$ Oct 14, 2020 at 16:41
  • $\begingroup$ How can I implement this in a micro? I could do something like triggering an ADC at fixed frequency. I was thinking also on using double buffer approach. I also need some floating point variables. Can you provide a pseudocode? $\endgroup$ Oct 14, 2020 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.