# RMS of Fundamental Component

1. ### jegues

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?

### Staff: Mentor

The implication being that 50μs sampling is sufficient to adequately represent the waveform for this purpose?

Are you wanting to perform the task in software or as a hardware implementation?

3. ### jegues

Yes.

In software. One limitation is that the code used to do so must be executed to completion every 50μs timestep.

Any ideas?

### Staff: Mentor

But if the waveform is periodic, there will be only one answer, one RMS value. Once that is established, to acceptable tolerance, what is there to update every 50μs?

You have no prior knowledge whether the cyclic period extends for some days, hours, or just milliseconds?? Your software will first have to establish this, undoubtedly.

What is the source of such a signal?

5. ### jegues

We are preforming the calculation every 50μs so the results appear in "real-time". This means that if the periodic waveform suddenly changes the RMS of the fundamental will change with it.

Does the problem become more manageable if I have the user provide the frequency of their periodic signal?

The input for example, could be either a voltage or current in a simulated circuit, or perhaps even a control signal in a control system.

Look forward to your thoughts.

6. ### anorlunda

400
But the RMS value is only defined for an integer number of whole cycles. If the period of the waveform you're measuring is longer than 50μs, then your goals are contradictory.

My suggestion to redefine "real time" to mean something longer than one complete cycle of the waveform, and calculate RMS at that interval.

You could define a rolling mean with a buffer big enough to hold one cycle's worth of samples. With each new sample,drop the oldest and add the newest. But if you did that, the definition of what your measurement means would be squishy and not worth the trouble. Your real problem is a bogus definition of "real time"

Oh yes, you said fundamental component too. To do that you need to use a low pass filter on the samples before calculating the RMS. The filter will add some phase shift (time delay) that could be large compared to 50μs, further clouding what a "real time" RMS at 50μs intervals would mean.

Last edited: Jul 7, 2014

### Staff: Mentor

If you know the frequency of the fundamental you'll know where to set your z domain filter to separate the fundamental from its harmonics. If you know the period, you know how many samples are needed to compute over, if using the FFT.

It's probably going to become relevant to your considerations: approximately what per cent of the total power is contained in the fundamental?

8. ### Averagesupernova

There is a bit of confusion here. RMS means the Root of the Mean of the Square(s). Since the word "Mean" is included it implies storing a number of samples to later be averaged. With a sine wave this is only necessary for one cycle. But it is implied in post #5 that the signal can suddenly change. So this means storing for longer. How is 'real time' to be defined? The OP hasn't said just what type of results are expected. Generally one has expectations of what the results will be before attempting to measure. Technically, "real-time" would not be averaged in any way. An analog scope displays voltage in real-time and the result is a graph.

9. ### sophiecentaur

13,259
If you want to do a good 'running' frequency analysis of your signal then you will need a long sequence of samples, suitably windowed or you could end up with some embarrassing artefacts - I could imagine two possible 'fundamentals' could emerge, for instance. How many sample intervals can you afford to wait before the analysis and what sort of frequency range are you expecting for the input waveform?

10. ### jegues

Assume we have an unknown peroidic input signal that we can obtain samples of every 50μs timestep. (We have the ability to access the input every 50μs timestep, that doesn't mean we HAVE too)

Assume that we know beforehand that the fundamental of this input signal equivalent to,

$$M_{1}sin(1t)$$

Then we expect the output (i.e. the RMS of the fundamental component) to be,
$$\frac{M_{1}}{\sqrt{2}}$$

Now if the input signal were to suddenly change such that the fundamental of this altered input signal is equivalent to,

$$M_{2}sin(1t)$$

Then we expect the output (i.e. the RMS of the fundamental component) to be,
$$\frac{M_{2}}{\sqrt{2}}$$

and so on for any arbitrary periodic input.

I would like to have my output transition from say,

$$\frac{M_{1}}{2}$$

to,

$$\frac{M_{2}}{2}$$

as quickly as possible.

Is it more clear what I am trying to achieve?

11. ### anorlunda

400
A sudden jump from M1 to M2 makes the signal non-sinusoidal which conflicts with your assumptions. Root-mean-square only has meaning for whole cycles, it has no instantaneous meaning.

If you report a change in RMS because just one sample deviated, then you may falsely report a momentary spike as representing a whole cycle's change in RMS value. In other words, reporting RMS measurements the way you propose will amplify noise.

If you filter the data to only fundamental frequency, then the momentary spike will be eliminated from the data and there will be no change to report after the first sample.

If the change is not a momentary spike, but rather a sustained change, then you must gather many samples from one or several whole cycles before jumping to the conclusion that the change should be reported. That means delaying the measurement until you are sure it's valid.

The problem is not with algorithm, it is with your requirements.

12. ### jegues

I specifically used the wording,

above because this could mean a cycle later.

13. ### sophiecentaur

13,259
You will find it difficult to determine the period with just one cycle - particularly if the frequency is changing. How would you analyse the signal and identify the peak of the fundamental of a squarish wave? There may be a fundamental flaw in your basic requirement if I understand your description properly. Is the waveform 'almost sinusoidal' or is it very complex? If it complex, you will need to look at it over more than one cycle to identify the period.

I think the reaction against your idea of "real time" requirement is a bit nit picking. It seems reasonable enough to me if you can accept some delay. Every measurement takes some time - there is always some built-in delay. I suspect you really mean a continuous series of measurements, rather than 'batch processing. The delay that is involved will depend upon several factors - including the ones already mentioned, like number of cycles involved in the processing and the nature of the waveform.

### Staff: Mentor

If you know ahead of time the frequency of the fundamental and it's fixed for each source, the simplest solution would be to pass the signal through an analog LPF specific to that source and connect the filter's (sine-wave) output directly to a voltmeter. Maybe use capacitive coupling to the filter to remove any DC component.

I'm curious to learn why you wish to disregard the power in the harmonic content? Also, is there likely to be appreciable noise on the signal? Should this be allowed for?

15. ### sophiecentaur

13,259
You're certainly right that noise could be a fresh can of worms and increase the processing time significantly.

16. ### anorlunda

400
Here is the original question.

Your question makes it sound like you want to do a new RMS calculation every 50μs. Later in the thread, you said something very different.

Why don't you start again from scratch? Tell in more detail what you do know about the frequency range and noise in the signal and what you hope to accomplish in terms of frequency of RMS calculations and tolerance for noise. If it is 100% unknown, then there is no answer. Then try to state your question more clearly. What do you expect from this forum short of the code?

17. ### jegues

I am trying to make the program work for the most general set of signals possible, so I'm intentionally not making any assumptions about what is known about the frequency range or noise in the input signal. The one limitation that is known is that the maximum rate at which I can sample the input signal is every 50μs.

Does assuming the fundamental frequency is within the range 0Hz < f < 1000Hz simplify the problem at all?

I want to calculate the RMS of only the fundamental component after every cycle of the input signal.

18. ### sophiecentaur

13,259
And what do you suppose that any answer you might get would actually correspond to? When you use the term "fundamental" you are implying (to be strict) the period of a sine wave of infinite length. Truncating an infinite train of sine waves is a form of Modulation. This will introduce uncertainty into the 'frequency' of any fundamental sin wave (spreading the spectrum from a single line into a band of frequencies. If you have a periodic looking signal for which the time between maxima is uncertain, all you could tell would be the sum of the squares of samples between the peaks. Not really a useful piece of information and it would not represent a true RMS value of any particular continuous wave.

I have a feeling that you need to get a bit more familiar with the basics of this stuff before you launch out on this exercise. Any routine you write could well yield some numerical values but they would have no meaning - or at least the numbers would need to be interpreted carefully because they cannot be a true 'RMS of a fundamental'.

You say you want your routine to work on a perfectly 'general' set of signals. What sort of interpretation would you expect if your particular signal consisted of the sum of two sine waves, of equal amplitude and different frequencies? What if your signal was part of a low pass filtered long pseudorandom sequence? What would be the fundamental frequency of that? (Answer = 1/(total repeat length of the sequence)

It just ain't that simple, you see. (Unless you are prepared to be much more specific about the actual nature of your signal).

### Staff: Mentor

May sound simpler in principle, but not in practice.

Consider 0 Hz < f

You do realize that, for example, for f = 0.00001 Hz the period is longer than one day. That's a lot of 50μs samples to store in readiness for processing, and a long time to wait for an updated RMS reading if someone changes the amplitude or frequency just slightly.

What would be the lowest useful frequency, for seeable practical purposes?

20. ### thankz

105
I just multiply by .707, I guess this only works for 60hz

Know someone interested in this topic? Share a link to this question via email, Google+, Twitter, or Facebook