Derivative of signal

Started by Mimar June 6, 2013
Hello,

could somebody give me an advice? At the moment I am solving interesting
problem. I have been using SW PLL with SOGI circuit to obtain grid
frequency since April and I have to say I am very happy, it works very
well. Accuracy is two decimal places. But my chief said me last week, we
will need to measure some changes (= first derivative, signal trend) of
resulting frequency soon. At first I used derivative with filtration from:
http://www.wseas.us/e-library/conferences/2007cscc/papers/561-186.pdf, but
it works very slowly and the calculated value is unstable - so I had to
implement moving average filter to smooth it. And secondly, I tested some
methods for numerical derivatives, but without positive result. Did
somebody solve  something of the sort? Any tricks to improve it?

Thanks!

P.S.: I am sorry, my English is very bad :-(.
On Thu, 06 Jun 2013 02:11:53 -0500, "Mimar" <94571@dsprelated> wrote:

>Hello, > >could somebody give me an advice? At the moment I am solving interesting >problem. I have been using SW PLL with SOGI circuit to obtain grid >frequency since April and I have to say I am very happy, it works very >well. Accuracy is two decimal places. But my chief said me last week, we >will need to measure some changes (= first derivative, signal trend) of >resulting frequency soon. At first I used derivative with filtration from: >http://www.wseas.us/e-library/conferences/2007cscc/papers/561-186.pdf, but >it works very slowly and the calculated value is unstable - so I had to >implement moving average filter to smooth it. And secondly, I tested some >methods for numerical derivatives, but without positive result. Did >somebody solve something of the sort? Any tricks to improve it?
Mimar, The calculation of the derivative of a real-world signal is always going to involve a compromise, as you have already seen. The theoretical definition of a derivative is the limit of calculations of rates of change over smaller and smaller intervals of time. In the real world it is not practical to measure changes over arbitrarily short time intervals. The noise (both additive and quantization) become more and more of a factor as the time interval decreases. So practical real-world derivatives must be based on some finite span of time. That is where the compromise comes in. You want to make that time span shorter to make the calculation responsive and quick. But you can't make it too short or else the noise in the signal makes the resulting calculation too noisy. You are doing the right thing in using a moving average. You will just have to find out how much averaging you need to achieve the accuracy you want. There is no magic solution. Robert Scott Hopkins, MN
On Thu, 06 Jun 2013 02:11:53 -0500, Mimar wrote:

> Hello, > > could somebody give me an advice? At the moment I am solving interesting > problem. I have been using SW PLL with SOGI circuit to obtain grid > frequency since April and I have to say I am very happy, it works very > well. Accuracy is two decimal places. But my chief said me last week, we > will need to measure some changes (= first derivative, signal trend) of > resulting frequency soon. At first I used derivative with filtration > from: > http://www.wseas.us/e-library/conferences/2007cscc/papers/561-186.pdf, > but it works very slowly and the calculated value is unstable - so I had > to implement moving average filter to smooth it. And secondly, I tested > some methods for numerical derivatives, but without positive result. Did > somebody solve something of the sort? Any tricks to improve it? > > Thanks! > > P.S.: I am sorry, my English is very bad :-(.
First: Your written English is a lot better than some engineers who are supposedly native English speakers, and it's a lot better than by best 2nd language. So don't apologize. Second: Derivatives, trends, etc., are problematic. Derivatives enhance high frequency content, and thus they enhance noise. Your "it works very slowly and the calculated value is unstable" is symptomatic of this issue. If I were in your shoes the first thing that I would want to do is to take the instantaneous frequency command going to the PLL oscillator and write it out a serial port, preferably every time the loop updated. I'd capture that into a text file then I'd take it back to my nice comfortable desk and I'd work on it there with Scilab or some other good analysis tool. The first thing I'd do is try to get the power spectral density of the signal while the PLL is tracking a known-steady AC wave. This would give me an idea of the measurement noise, which will, in turn, put a lower limit on the best-case "fast and stable" reading that I could expect to get out of the frequency trend (note that in this case "fast" and "stable" are working against each other -- to get fast you need a wider bandwidth, to get stable you need less. "Instantaneous and dead quiet" is impossible unless you can get your measurement noise down). Then I might experiment with various algorithms on that data. This will go a lot quicker than cutting and trying on an embedded app, and if you're careful about how you go about it you'll be able to take whatever result you like and put it into the embedded app. After that I'd consult with my boss to figure out if he can settle for slow and stable, fast and jumpy, or time spent flogging the phase measurement noise down. Third: By definition you're going to end up with a transfer function that (z - 1) in the numerator. Your job is to find the best low-pass filter to follow that (z - 1) term with. Whether it is an IIR filter, a FIR filter, a moving average (which should maybe have the title "Worst FIR Lowpass Ever") or some combination will come out of your experimentation. -- My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com
On 6/6/2013 2:11 AM, Mimar wrote:


> could somebody give me an advice?
Put nonlinear peak-clipping function after the differentiator before averaging. //------------- Q: Why it is impossible to have sex in Red Square in Moscow ? A: Because every bystander idiot would be trying to give his invaluable advice. Vladimir Vassilevsky DSP and Mixed Signal Designs www.abvolt.com
On Thu, 06 Jun 2013 14:56:01 -0500, Vladimir Vassilevsky wrote:

> On 6/6/2013 2:11 AM, Mimar wrote: > > >> could somebody give me an advice? > > > Put nonlinear peak-clipping function after the differentiator before > averaging.
And hope that it actually works. -- My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com
On Thursday, June 6, 2013 7:11:53 PM UTC+12, Mimar wrote:
> Hello, > > > > could somebody give me an advice? At the moment I am solving interesting > > problem. I have been using SW PLL with SOGI circuit to obtain grid > > frequency since April and I have to say I am very happy, it works very > > well. Accuracy is two decimal places. But my chief said me last week, we > > will need to measure some changes (= first derivative, signal trend) of > > resulting frequency soon. At first I used derivative with filtration from: > > http://www.wseas.us/e-library/conferences/2007cscc/papers/561-186.pdf, but > > it works very slowly and the calculated value is unstable - so I had to > > implement moving average filter to smooth it. And secondly, I tested some > > methods for numerical derivatives, but without positive result. Did > > somebody solve something of the sort? Any tricks to improve it? > > > > Thanks! > > > > P.S.: I am sorry, my English is very bad :-(.
You could design a simple control loop with an integrator in the feedback path. This will give you band-limited differentiation ie a slope of 6dB/octave.
On 6/6/2013 3:31 PM, Tim Wescott wrote:
> On Thu, 06 Jun 2013 14:56:01 -0500, Vladimir Vassilevsky wrote: > >> On 6/6/2013 2:11 AM, Mimar wrote: >> >> >>> could somebody give me an advice? >> >> >> Put nonlinear peak-clipping function after the differentiator before >> averaging. > > And hope that it actually works. >
Of course it does. By nature of the problem, power frequency can't change fast. There could be jerks of phase though. BTW, such an old whore like you could suggest something more fun then a page of truisms and bla-bla-bla. VLV
On 6/6/2013 4:11 PM, gyansorova@gmail.com wrote:
> On Thursday, June 6, 2013 7:11:53 PM UTC+12, Mimar wrote: >> >> could somebody give me an advice? At the moment I am solving >> interesting problem. I have been using SW PLL with SOGI circuit to >> obtain grid frequency
> > You could design a simple control loop with an integrator in the > feedback path. This will give you band-limited differentiation ie a > slope of 6dB/octave.
Good point. As the OP is using PLL, the output of phase detector is derivative of frequency. VLV
On 6/7/2013 12:56 PM, Vladimir Vassilevsky wrote:
> On 6/6/2013 4:11 PM, gyansorova@gmail.com wrote: >> On Thursday, June 6, 2013 7:11:53 PM UTC+12, Mimar wrote: >>> >>> could somebody give me an advice? At the moment I am solving >>> interesting problem. I have been using SW PLL with SOGI circuit to >>> obtain grid frequency > > >> >> You could design a simple control loop with an integrator in the >> feedback path. This will give you band-limited differentiation ie a >> slope of 6dB/octave. > > Good point. As the OP is using PLL, the output of phase detector is > derivative of frequency. > > VLV
On 6/7/2013 12:56 PM, Vladimir Vassilevsky wrote: > On 6/6/2013 4:11 PM, gyansorova@gmail.com wrote: >> On Thursday, June 6, 2013 7:11:53 PM UTC+12, Mimar wrote: >>> >>> could somebody give me an advice? At the moment I am solving >>> interesting problem. I have been using SW PLL with SOGI circuit to >>> obtain grid frequency > > >> >> You could design a simple control loop with an integrator in the >> feedback path. This will give you band-limited differentiation ie a >> slope of 6dB/octave. > > Good point. As the OP is using PLL, the output of phase detector is > derivative of frequency. > > VLV It still needs filtering. Digital approximations to derivatives come in many forms. The simplest and most intuitive is simply y[n]=x[n-1]-x[n]. For many applications, y[n]=.5(x[n-2]-2.c[n-1]+x[n]) is better. The cost is an extra clock of latency. Rick Lyons improves on that with two more delay terms and the corresponding extra latency. I'm not certain that I'm at liberty to provide more details. I expect that he will. Jerry -- Engineering is the art of making what you want from things you can get. &#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095; -- Engineering is the art of making what you want from things you can get. &#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;
On 6/7/2013 10:21 AM, Vladimir Vassilevsky wrote:
 > On 6/6/2013 3:31 PM, Tim Wescott wrote:
 >> On Thu, 06 Jun 2013 14:56:01 -0500, Vladimir Vassilevsky wrote:
 >>
 >>> On 6/6/2013 2:11 AM, Mimar wrote:
 >>>
 >>>
 >>>> could somebody give me an advice?
 >>>
 >>>
 >>> Put nonlinear peak-clipping function after the differentiator before
 >>> averaging.
 >>
 >> And hope that it actually works.
 >>
 >
 > Of course it does. By nature of the problem, power frequency can't
 > change fast. There could be jerks of phase though.
 >
 > BTW, such an old whore like you could suggest something more fun then a
 > page of truisms and bla-bla-bla.

Good Lord, Vlad! Some of us get used to your excesses, but you seem to 
have gotten more extreme during my absence.

Jerry
-- 
Engineering is the art of making what you want from things you can get.
&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;&macr;