Calculating RMS of Fundamental Component for Unknown Periodic Input Signal

In summary, the conversation discusses the calculation of the RMS for the fundamental component of an unknown periodic input signal. The implication is that 50μs sampling is sufficient to accurately represent the waveform. The task is desired to be performed in software every 50μs timestep, with the limitation that the code must be executed to completion within that time frame. The source of the signal could be a simulated circuit or a control system. However, there is a contradiction in trying to calculate the RMS value in real-time for a signal with a longer period. Suggestions are made to redefine "real-time" and to use a low pass filter to calculate the fundamental component. It is also suggested to have the user provide the frequency of their signal for better
  • #1
jegues
1,097
3
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?
 
Engineering news on Phys.org
  • #2
jegues said:
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?
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
NascentOxygen said:
The implication being that 50μs sampling is sufficient to adequately represent the waveform for this purpose?

Yes.

NascentOxygen said:
Are you wanting to perform the task in software or as a hardware implementation?
In software. One limitation is that the code used to do so must be executed to completion every 50μs timestep.

Any ideas?
 
  • #4
jegues said:
Yes.


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

Any ideas?
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
NascentOxygen said:
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?

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.

NascentOxygen said:
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.

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

NascentOxygen said:
What is the source of such a 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
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:
  • #7
jegues said:
Does the problem become more manageable if I have the user provide the frequency of their periodic signal?
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
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
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
Averagesupernova said:
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.

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,

[tex]M_{1}sin(1t)[/tex]

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

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


[tex]M_{2}sin(1t)[/tex]


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

and so on for any arbitrary periodic input.

I would like to have my output transition from say,

[tex]\frac{M_{1}}{2}[/tex]

to,


[tex]\frac{M_{2}}{2}[/tex]

as quickly as possible.

Is it more clear what I am trying to achieve?
 
  • #11
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
anorlunda said:
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.

I specifically used the wording,


as quickly as possible.

above because this could mean a cycle later.
 
  • #13
jegues said:
I specifically used the wording,




above because this could mean a cycle later.

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.
 
  • #14
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
You're certainly right that noise could be a fresh can of worms and increase the processing time significantly.
 
  • #16
Here is the original question.

jegues said:
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?

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
anorlunda said:
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

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?

anorlunda said:
and what you hope to accomplish in terms of frequency of RMS calculations and tolerance for noise.

I want to calculate the RMS of only the fundamental component after every cycle of the input signal.
 
  • #18
jegues said:
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.

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).
 
  • #19
jegues said:
Does assuming the fundamental frequency is within the range 0Hz < f < 1000Hz simplify the problem at all?
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
I just multiply by .707, I guess this only works for 60hz
 
  • #21
thankz said:
I just multiply by .707, I guess this only works for 60hz

Works for any frequency as long as it is a sine wave.
 
  • #22
I'm sure it will work for any number of waveforms. :wink:
 
  • #23
This question is impossible to answer. If we knew the signal and noise you were expecting and why you wanted the RMS result, then we might be able to resolve the multiple ambiguities in your question and propose a viable solution.

How do you define the fundamental? Is it the greatest amplitude sine wave component present?
Consider the signal Sin(t) + 2*Sin(2t); where the fundamental is smaller amplitude than the second harmonic.

Maybe you could implement a digital Phase Locked Loop that tracks the phase of the principal signal with a rotating unit vector. Synchronously detect the input signal by multiplying input by the reference vector. Adjust the rotation frequency of the reference by the synchronously detected phase error. The synchronously detected vector amplitude is the RMS value.

http://en.wikipedia.org/wiki/Phase-locked_loop#Implementing_a_digital_phase-locked_loop_in_software
 
Last edited:
  • #24
NascentOxygen said:
What would be the lowest useful frequency, for seeable practical purposes?

To simplify things, let's limit the frequency range between 0.1Hz < f < 1000Hz.

If we knew the signal and noise you were expecting and why you wanted the RMS result, then we might be able to resolve the multiple ambiguities in your question and propose a viable solution.

The signal is likely to be a voltage or current from within a power system. At this point I am unsure what level of noise will be present, but perhaps knowing that the signal is coming from a power system context, you can infer what level of noise will be present, but I'm not sure.

I want the RMS of the fundamental because this is a common index that people use in a variety of different applications. (i.e. for protective relays applications etc.)

How do you define the fundamental? Is it the greatest amplitude sine wave component present?
Consider the signal Sin(t) + 2*Sin(2t); where the fundamental is smaller amplitude than the second harmonic.

The fundamental is always going to be the fundamental component, not simply the greatest amplitude sine wave component present.

Are we getting closer to a clearer picture? Please do not hesitate to ask for more information if it is still necessary.
 
  • #25
If the "power system" means the grid, then the frequency will be 60 (or 50) +- 0.1 or so. Why would you need 0.1 to 1000 Hz?

Your answer as to why fundamental component is vague and sounds false. In most applications, the RMS of the complete signal is more useful and easier to calculate. In most locations on the power grid, the harmonic content is small, so that the RMS of the total signal and the RMS of the fundamental component are almost the same value.

In an earlier post, you said that you would be willing to wait for a whole cycle or more to be sure that a change is not just a spike. Now you say the calculation must finish every 50 microseconds. Why? Your answers are contradictory and don't make sense.

What exactly is your application?
 
  • #26
anorlunda said:
If the "power system" means the grid, then the frequency will be 60 (or 50) +- 0.1 or so. Why would you need 0.1 to 1000 Hz?

Because it may also be used in some controls applications where the frequency of the input signal is not 60 or 50 +- 0.1 Hz.

anorlunda said:
Your answer as to why fundamental component is vague and sounds false. In most applications, the RMS of the complete signal is more useful and easier to calculate. In most locations on the power grid, the harmonic content is small, so that the RMS of the total signal and the RMS of the fundamental component are almost the same value.

I need the fundamental component. The reason I was given is that this is a commonly used index in a variety of applications.
anorlunda said:
In an earlier post, you said that you would be willing to wait for a whole cycle or more to be sure that a change is not just a spike. Now you say the calculation must finish every 50 microseconds. Why?

The output must be updated after every full cycle of the input, but the code for the program must be executed to completion every 50μs. When the code is executed to completion every 50μs, this does not necessarily mean that the output is updated.
 
  • #27
hmmmm, RMS you say ?
you square most recent of the individual readings, then a new mean of all your accumulated squares, then take square root of that mean ?
I suppose one could , every 50 usec, do something akin to that
but shouldn't he pick a number of samples to include in his mean ? Else after 50 seconds he has a million samples to deal with.

please excuse my simple-mindedness
 
  • #29
anorlunda said:
A google search on "digital voltmeter rms algorithm" finds this http://http://www.ni.com/white-paper/2966/en/, plus hundreds more web pages on the subject. Start there.

That's OK for a clean 'sine-looking' waveform and but it that the case here? i.e. is there a single identifiable frequency in his signal and is there just a small amount of shash on it? But he doesn't seem to want to say. The whole thing still doesn't hold together for me. Something's missing.
 
  • #30
forgive my ignorance but I've never heard of the term 'shash', what is it?
 
  • #31
jim hardy said:
hmmmm, RMS you say ?
you square most recent of the individual readings, then a new mean of all your accumulated squares, then take square root of that mean ?
I suppose one could , every 50 usec, do something akin to that
Yes, ... but no. That would give the RMS of the signal, but OP does not want that. Rather, it's the RMS of the fundamental component in the signal that is being sought. The harmonics and noise need first be discarded.
 
  • #32
Shash is a slang word meaning all the parts of a signal you didn't want.

There are many sites on the net which can help you with such expressions. Include "slang" in the search terms.
 
  • #33
jegues said:
Because it may also be used in some controls applications where the frequency of the input signal is not 60 or 50 +- 0.1 Hz.
If that spec was fixed, it would eliminate the need for some sort of adaptive self-tuning filter, something which will take multiple cycles to establish.

I need the fundamental component. The reason I was given is that this is a commonly used index in a variety of applications.
My unanswered question from back here https://www.physicsforums.com/showpost.php?p=4791783&postcount=7 still needs to be addressed.
 
  • #34
NascentOxygen said:
If that spec was fixed, it would eliminate the need for some sort of adaptive self-tuning filter, something which will take multiple cycles to establish.


My unanswered question from back here https://www.physicsforums.com/showpost.php?p=4791783&postcount=7 still needs to be addressed.

Sorry NascentOxygen, but I haven't been given any information regarding the percentage of maximum power contained within the fundamental.
 
  • #35
Here's my first attempt at writing some code. I'll show the header file followed by the actual code file.

Header file:
Code:
/* DO NOT EDIT THIS FILE */

MODEL_TYPE: CTL

#define PI        3.1415926535897932384626433832795   // definition of PI                 
#define TWOPI     6.283185307179586476925286766559    // definition of 2.0*PI             
#define E         2.71828182845904523536028747135266  // definition of E                  
#define EINV      0.36787944117144232159552377016147  // definition of E Inverse (1/E)    
#define RT2       1.4142135623730950488016887242097   // definition of square root 2.0    
#define RT3       1.7320508075688772935274463415059   // definition of square root 3.0    
#define INV_ROOT2 0.70710678118654752440084436210485                                      

INPUTS:
  double NA;
  double NB;
  double NC;
  double N1;

OUTPUTS:
  double Out;

PARAMETERS:
  int    Mode;      //Operation Mode
  int    pu;        //Scale Output to per unit?
  double Sc;        //Rated L-L (3Ph) or L-N (1Ph) Input
  int    LL;        //For 3 Phase display output as
  int    unit;      //Units to display on meter
  int    solMethod; //Single Phase Solution Method
  double fn;        //Nominal Frequency of Input Signal

Component Code:
Code:
VERSION:
3.001

/* Include file below is generated by C-Builder    */
/* and contains the variables declared as -        */
/* PARAMETERS, INPUTS, OUTPUTS . . .               */
#include "myRMSwfund.h"


STATIC:

/* ----------------------------------------------- */
/* Variables declared here may be used in both the */
/* RAM: and CODE: sections below.                  */
/* ----------------------------------------------- */
/*    double dt;  */
///////////////////////////////////////////////////////
double dt;
double T;
double integral;
int numdt;
int index;
int i;
int N;
double inputSamples[8];
int dtSampleDivisor;
int currSampleIndex;
double ReX;
double ImX;
double WR1[8];
double WI1[8];
double C1;
//////////////////////////////////////////////////////
/* - E n d   o f   S T A T I C :   S e c t i o n - */

RAM_FUNCTIONS:

/* ----------------------------------------------- */
/* This section should contain any 'c' functions   */
/* to be called from the RAM section (either       */
/* RAM_PASS1 or RAM_PASS2). Example:               */
/*                                                 */
/* static double myFunction(double v1, double v2)  */
/* {                                               */
/*     return(v1*v2);                              */
/* }                                               */
/* ----------------------------------------------- */
///////////////////////////////////////////////////////////////////////
static int round(double num){
	int temp;
	if (num > 0)
		temp = (int)floor(num + 0.5);
	else
		temp = (int)ceil(num - 0.5);
	return temp;
}
///////////////////////////////////////////////////////////////////////
RAM:

/* ----------------------------------------------- */
/* Place C code here which computes constants      */
/* required for the CODE: section below.  The C    */
/* code here is executed once, prior to the start  */
/* of the simulation case.                         */
/* ----------------------------------------------- */
/*    dt= getTimeStep();                           */
/////////////////////////////////////////////////////////////
dt= getTimeStep();
T = 1/fn;
numdt = round(T/dt);
index = 1; //Should index start at 1 or 0?
integral = 0;
ReX = 0;
ImX = 0;
N = 8;
currSampleIndex = 0;
dtSampleDivisor = trunc(numdt/N);
C1 = 2.0/N;
for (i = 0; i < N; i++){
	WR1[i] = C1*cos((TWOPI/N)*i);
	WI1[i] = C1*sin((TWOPI/N)*i);
}
/////////////////////////////////////////////////////////////

/* ---- E n d   o f   R A M :   S e c t i o n ---- */

CODE:

/* ----------------------------------------------- */
/* Place C code here which runs on the RTDS. The   */
/* code below is entered once each simulation      */
/* step.                                           */
/* ----------------------------------------------- */
//double rms3Ph(float nodeA, float nodeB, float nodeC, double scale) 

if(index > numdt){ //If it has been a full cycle of the input, reset indices
	index = 1;
	currSampleIndex = 0;
}
if(index % dtSampleDivisor == 0){ //If it's time to take a sample, take one and compute the Re and I am parts in f domain
	ReX = 0;
	ImX = 0;
	inputSamples[currSampleIndex] = N1;
	for(i = 0; i < N; i++){
		ReX = ReX + inputSamples[i]*WR1[i];
		ImX = ImX - inputSamples[i]*WI1[i];			
	}
	currSampleIndex++;
	Out = sqrt(ReX*ReX + ImX*ImX)/sqrt(2);
}
index++;
/* ---- E n d   o f   C O D E :  S e c t i o n --- */

Here is the test case I've developed for the testing of fundamental RMS component. As you can see I generate three sinusoidal harmonics and add them together to create my input signal.

Test Case Picture

[tex]Input = rms1\sqrt{2}sin(2\pi(1)60t)+ rms2\sqrt{2}sin(2\pi(2)60t) + rms4\sqrt{2}sin(2\pi(4)60t)[/tex]

In this particular test case we have,

[tex]rms1 = 50.0, \quad rms2 = 20.0, \quad rm4 = 20.0[/tex]

Here are the simulation results,
Legend:
Input - Input Signal
fRMSOutput - Fundamental RMS component output
tRMSOutput - Regular RMS component output (computes the total RMS)

With a short simulation time (0.2s) we observe the following waveforms,

Short Simulation Time Results

If we look at the results over a longer simulation time we can see the results are oscillating over time,

Long Simulation Time Results

However, if I select the frequency of the fundamental such that it is an integer multiple of the timestep these deviations go away. If,

[tex]f = 50Hz, \quad dt = 50\mu s \Rightarrow \frac{50}{50\times10^{-6}} = 1 \times 10^{6}[/tex]

we observe the following results,

Integer Multiple of Timestep Results

From these results I'm thinking the smaller deviations visible in the short simulation time results are because the samples aren't being taken at the same points each cycle. This is happening because the peroid of the waveform does not fit into an integer multiple of timesteps.

Another weird result I found is that with the fundamental frequency set to 60Hz (i.e. not an integer multiple of the timestep) if I increase the number of samples per cycle from 8 to 32 the deviations disappear completely, but the results still aren't entirely accurate.

32 Samples Per Cycle Results

Please let me know of your thoughts/comments/suggestions. Any idea why I am seeing some of these discrepancies in my results?

Thanks!
 

Attachments

  • testcase.png
    testcase.png
    31 KB · Views: 629
  • resultssmallt.jpg
    resultssmallt.jpg
    34 KB · Views: 625
  • resultslarget.jpg
    resultslarget.jpg
    31 KB · Views: 655
  • intdtresults.jpg
    intdtresults.jpg
    31.4 KB · Views: 595
  • 32samples.jpg
    32samples.jpg
    31.5 KB · Views: 625

Similar threads

  • Electrical Engineering
Replies
11
Views
3K
  • Electrical Engineering
Replies
18
Views
4K
  • Electrical Engineering
Replies
11
Views
1K
Replies
2
Views
1K
  • Electrical Engineering
Replies
4
Views
799
  • Electrical Engineering
Replies
5
Views
2K
Replies
6
Views
3K
  • Electrical Engineering
2
Replies
63
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
6K
  • Electrical Engineering
Replies
4
Views
296
Back
Top