RMS of Fundamental Component

NorthGuy

Joined Jun 28, 2014
611
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.
Imagine a sine wave. If you're at the peak now, after time t passes, you sample will be cos(ωt). It will be some error to it, but otherwise it is totally predictable. If you put your samples on the graph it'll be a sine wave, which will also have some frequency.

So, we have three different frequencies: data frequency, sampling frequency, and the frequency of sine wave that you would get if you would plot your data - we'll call it visible frequency. With me so far?

Unless you can control sampling frequency, your have no control of what visible frequency you get. It might happen to be very low.

An example from your post. Data frequency is 60Hz. Sampling frequency is 60.001Hz. Visible frequency is 0.001Hz.

If visible frequency is low, and you start sampling from the peak, you will be sampling the peak for quite a while and your average will be biased. Then you finally reach zero, at which point your result will be correct. But then you'll continue sampling around zero, so your result will start decreasing below true value again until you reach the next peak, and so on.

In case of 0.001Hz, you'll get correct results at 250, 500, 750, 1000, 1250 etc., but between 0 and 250 your result will be over true value, same between 500 and 750 and so on. Results you get between 250 andd 500, 750 and 1000 etc will be less than true value. To get the bias withing 1%, you'll need to continue sampling for about 50 cycles, 50000 seconds, almost 14 hours, which is next to useless.
 

MrChips

Joined Oct 2, 2009
30,802
There is one little snag. Sampling a signal frequency of 60Hz with a sampling frequency of 60.001Hz violates the sampling theorem. The sampling frequency should be at least twice the maximum data frequency.

So you need two things:

1) a sampling frequency greater than 120Hz

2) an anti-aliasing filter, i.e. a low pass filter that attenuates frequencies above 60Hz.

Getting back to the OP's situation, if the sampling frequency is 20kHz, make sure you install an anti-aliasing filter that attenuates everything above 10kHz as Papabravo has already indicated.

If the signal of interest is 60Hz, make sure you sample for multiple whole cycles of 60Hz. For example, if you sampled for 50ms (1000 samples) you would capture 3 cycles at 60Hz.
 
Last edited:

Lestraveled

Joined May 19, 2014
1,946
The only time you need to satisfy the Nyquist requirement is when you are doing frequency domain processing, so there is no requirement to have a 2X sample speed in this application. I don't care about false images, or aliasing. I am solving for amplitude only. I do not need to have a sample occur in every cycle. The sample rate can be far below the signal frequency. The only requirement is that the sample frequency and the signal are not coherent. Basically all that needs to be done is to statistically determine the RMS value of your samples over a long enough period of time.

Mark
 

Papabravo

Joined Feb 24, 2006
21,225
I'm not strongly persuaded by any of the arguments presented. It should be a simple proposition to test. Construct a composite waveform with a principle component having a known RMS value and see if you can recover that value by any of the proposed methodologies from the composite waveform. If it works, this would not be a proof of the method, but if it doesn't work then the method has a serious flaw.

Based on that experiment perhaps someone with more rigor than I possess can offer a sounder theoretical basis for the correct method.
 

Lestraveled

Joined May 19, 2014
1,946
I'm not strongly persuaded by any of the arguments presented. It should be a simple proposition to test. Construct a composite waveform with a principle component having a known RMS value and see if you can recover that value by any of the proposed methodologies from the composite waveform.........

Good call!

Like my signature reads,.....one good experiment...... I'll work on it.

Mark
 

THE_RB

Joined Feb 11, 2008
5,438
I can do it. ;)

I would sample at two or three chosen frequencies and use some smart algortihm to determine the RMS from those two or three data sets. Fast, and accurate (enough).
 

Thread Starter

jegues

Joined Sep 13, 2010
733
Here's my first attempt at writing some code. I'll show the header file followed by the actual code file.

Header file:
Rich (BB 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:
Rich (BB 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 = C1*cos((TWOPI/N)*i);
                 WI1 = 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 Im parts in f domain
                 ReX = 0;
                 ImX = 0;
                 inputSamples[currSampleIndex] = N1;
                 for(i = 0; i < N; i++){
                                ReX = ReX + inputSamples*WR1;
                                ImX = ImX - inputSamples*WI1;                                        
                 }
                 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.

http://forum.allaboutcircuits.com/attachment.php?attachmentid=70633&stc=1&d=1405088251

\(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)\)

In this particular test case we have,

\(rms1 = 50.0, \quad rms2 = 20.0, \quad rm4 = 20.0\)

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,

http://forum.allaboutcircuits.com/attachment.php?attachmentid=70634&stc=1&d=1405088251

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

http://forum.allaboutcircuits.com/attachment.php?attachmentid=70635&stc=1&d=1405088251

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

\(f = 50Hz, \quad dt = 50\mu s \Rightarrow \frac{50}{50\times10^{-6}} = 1 \times 10^{6}\)

we observe the following results,

http://forum.allaboutcircuits.com/attachment.php?attachmentid=70636&stc=1&d=1405088251

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.

http://forum.allaboutcircuits.com/attachment.php?attachmentid=70637&stc=1&d=1405088251

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

Thanks!
 

Attachments

Papabravo

Joined Feb 24, 2006
21,225
@jegues, Congratulations on a truly excellent post.

What this feels like, from an abstact point of view, is a problem that is without a unique solution. For example, the intersection of two non-parallel lines is a unique point. In our case there are literally an infinite number of ways to sample an "unknown" signal. Each way of sampling the signal provides a different answer on the RMS value of the fundamental component. Even if we know the frequency of the fundamental component we still get results that are hard to square with our expectations, that there is a unique solution to the question about the RMS value of the fundamental component.

When you do a DFT on the unknown input signal, the output is related to the power of the various components. Would that be an acceptable substitute for RMS voltage? I'd be interested to see if that will at least allow you to identify the frequency components in your test signal.
 
Last edited:

Thread Starter

jegues

Joined Sep 13, 2010
733
Each way of sampling the signal provides a different answer on the RMS value of the fundamental component. Even if we know the frequency of the fundamental component we still get results that are hard to square with our expectations, that there is a unique solution to the question about the RMS value of the fundamental component.
Maybe by knowing frequency of the fundamental component we can deduce how we should sample the input signal. This way, at least the results for different input signals with different fundamental frequencies should be somewhat consistent with one another.

When you do a DFT on the unknown input signal, the output is related to the power of the various components. Would that be an acceptable substitute for RMS voltage? I'd be interested to see if that will at least allow you to identify the frequency components in your test signal.
It may be a reasonable substitute, but my requirements are still to compute the RMS of the fundamental component.
 

Lestraveled

Joined May 19, 2014
1,946
You changing your sample interval to an integral multiple of the fundamental and the trms oscillations stopped, suggests to me a bias due to the simulated elements being inherently locked together. I don't believe that is can be simulated without addressing this issue. If your measurements are not random (Gaussian) then biases will emerge. I think the drastic change in trms when You changed your sample interval to an integral multiple of the fundamental strongly suggests this.

I currently do not have the means to test this on my bench, but, I will.

Mark
 

Lestraveled

Joined May 19, 2014
1,946
I think this analogy applies:

You are on one side of a fence, on the other side is dog pacing back and forth. You do not know what a dog is, you have never seen one before. There is a hole in the fence that you can look through, but only momentarily and with a limited view. Each time you look through the hole you see a small part of the dog. If, when you look and the dogs pacing, are not synchronous (random relative to each other), then you will eventually see all parts of the dog and will be able to form an accurate picture of the dog. If your looking, and the dogs pacing, is synchronous, then there are parts of the dog you will never see and will result in you forming a distorted picture of the dog.

Mark
 
Last edited:
Top