# RMS of Fundamental Component

Discussion in 'Programmer's Corner' started by jegues, Jul 6, 2014.

1. ### jegues Thread Starter Well-Known Member

Sep 13, 2010
735
43
Every 50μs I have access to one sample of an unknown peroidic input signal and I am looking to calculate the RMS of the fundamental component. Is there any convenient ways one can think of doing this?

2. ### Papabravo Expert

Feb 24, 2006
11,078
2,157
Just based on the information you have given I would say no. You cannot determine the frequency of the fundamental component. You did not say the input signal was band-limited by an anti-aliasing filter so you're just SOL.

3. ### Lestraveled Well-Known Member

May 19, 2014
1,957
1,224
If you assume random sampling, the more samples you take the more accurate your RMS calculation becomes over time. You can use delta RMS per unit time to determine accuracy. Of course this only works with non varying amplitudes.......I think.

4. ### Papabravo Expert

Feb 24, 2006
11,078
2,157
The RMS calculation requires that you square the waveform, take the mean over one period, and take the square root of that. You can have a varying amplitude but you must know the length of a period.

5. ### jegues Thread Starter Well-Known Member

Sep 13, 2010
735
43
So if the user specified the frequency of the unknown periodic waveform, would this be possible? Is this specified frequency the same as the frequency of the fundamental component?

6. ### Papabravo Expert

Feb 24, 2006
11,078
2,157
If you know the frequency of the fundamental component you have a shot. You also have to be careful that high frequencies don't alias for lower frequencies. That is why you need an analog anti-aliasing filter ahead of ANY digital process you plan to apply.

7. ### Lestraveled Well-Known Member

May 19, 2014
1,957
1,224
There is not a frequency term in the RMS formula. If you need one, make it scalar based on the number of samples and the sample interval.

8. ### NorthGuy Active Member

Jun 28, 2014
611
122
But frequency is important nonetheless. For example, if the signal frequency is 60Hz and your sampling frequency is 60Hz too, you'll be sampling all peaks (and overestimate RMS) or all zeroes (and underestimate). There are other frequency effects too.

Therefore, if you wat to measure RMS you need to choose your sampling frequency carefully, so that you don't get in troubles for your expected signal frequency range.

9. ### Lestraveled Well-Known Member

May 19, 2014
1,957
1,224
Northguy
What you are describing only occurs when the sample rate and the frequency of the unknown signal are coherent (phase locked). The OP indicated that this is not the case. If I sample a 60 Hz sine wave at a 60 Hz rate I will eventually get enough samples to accurately describe its RMS value if, and only if, the two clocks are not coherent. The time period in this case is the reciprocal of the difference in their frequency. For instance: 60.000 Hz minus 60.001 Hz = .001HZ or 1000 seconds.

10. ### jegues Thread Starter Well-Known Member

Sep 13, 2010
735
43
So how do I proceed if this information is known?

11. ### MrChips Moderator

Oct 2, 2009
14,281
4,195
It really depends on your exact situation and what you are trying to achieve.

Trying to measure the amplitude of AC mains voltage is quite different from measuring an arbitrary sine wave signal buried in noise.

If the situation is the latter case and you know the frequency of the signal, I would acquire at minimum, 10 samples per period. 20-100 samples would be even better.

There are linear least squares algorithms at will allow you to extract amplitude, frequency, phase and DC offset of the signal buried in noise.

12. ### Papabravo Expert

Feb 24, 2006
11,078
2,157
Over one period
Square the samples
Take the mean
Take the square root

13. ### shteii01 AAC Fanatic!

Feb 19, 2010
3,922
601
50 us. That be sampling frequency of 20 kHz. You can use that to sample signals that have frequencies from 0-10 kHz.

Collect the samples. From them determine the frequency of the signal (or ask the signal generator to tell you what the frequency is ahead of time). Then do the math.

14. ### Papabravo Expert

Feb 24, 2006
11,078
2,157
You STILL need an analog anti-aliasing filter ahead of your sampler, or your results will in fact be garbage.

15. ### jegues Thread Starter Well-Known Member

Sep 13, 2010
735
43
This is the RMS of the sampled waveform, not necessairly the RMS of its fundamental component, right?

16. ### NorthGuy Active Member

Jun 28, 2014
611
122
Right. And if you sample this for 1000 seconds, the result will be different than if you sample it for 1500 seconds.

The errors will happen if your sampling frequency coinsides with any of the harmonics of the signal frequency. To avoid such effects you will have to employ a low-pass filter as Papabravo said. As a result of the filtering, you will only get good results only if signal frequency is substantially less than your sampling frequency.

You will also get in troubles if you try to measure the signal frequency which is too low. Say, if you take 100 consecutive samples at 1MHz to measue RMS of 60Hz signal, the result will be pretty much random.

Therefore, you cannot use fixed sampling frequency and pre-determined number of samples to effectively measure RMS for all possible frequencies of the signal.

17. ### Lestraveled Well-Known Member

May 19, 2014
1,957
1,224
NorthGuy
Lets look at from a different point of view. Suppose the signal being sampled was Gaussian noise. The longer you sample, the more accurately you can approximate what the RMS value is.

Any agreement?

Also, I do realize I was "off track" because the OP was asking to measure the fundamental amplitude not full spectrum.

Mark

18. ### NorthGuy Active Member

Jun 28, 2014
611
122
No doubts. This is becuase errors are independent and autocorrelations are zero.

19. ### Lestraveled Well-Known Member

May 19, 2014
1,957
1,224
NorthGuy
Then I don't understand why you can't take the same approach with an unknown signal? Use the delta RMS as your indication of when you have taken enough samples.

Mark

20. ### Papabravo Expert

Feb 24, 2006
11,078
2,157
If the ANALOG ANTI_ALIASING FILTER that I've mentioned on multiple occasions is used there will only be the fundamental.