Hello I=92m sampling a signal at 1000Hz rate. I need to find the derivative of the signal every 100ms. I have tried to calculate it like this every 100ms: dx =3D (x_old =96 x) / 0.1 x_old =3D x x is the signal at that moment. But I=92m thinking of how I could use the other 99 samples to get a better approximation of the derivative over 100ms. If I could do a least square fit of a straight line of 100 samples and take the slope of that line as the derivative. Any ideas?
Calculate better derivative of an signal?
Started by ●April 20, 2011
Reply by ●April 20, 20112011-04-20
On Apr 20, 4:29=A0pm, Lox <skolpojke...@yahoo.se> wrote:> > If I could do a least square fit of a straight line of 100 samples and > take the slope of that line as the derivative.You could exactly fit a polynomial of degree 99 to the 100 samples and then find the derivative of that instead. Is there a reason that you are not telling us why least-squares fitting of a straight line to 100 samples is a more appropriate solution? --Dilip Sarwate
Reply by ●April 20, 20112011-04-20
On 04/20/2011 02:29 PM, Lox wrote:> Hello > > I�m sampling a signal at 1000Hz rate. I need to find the derivative of > the signal every 100ms. > > I have tried to calculate it like this every 100ms: > > dx = (x_old � x) / 0.1 > x_old = x > > x is the signal at that moment. > > But I�m thinking of how I could use the other 99 samples to get a > better approximation of the derivative over 100ms. > > If I could do a least square fit of a straight line of 100 samples and > take the slope of that line as the derivative. > > Any ideas?Define what "better" means within the context of the larger problem that you're trying to solve. If the solution doesn't drop out, you'll at least be a lot closer to it. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●April 21, 20112011-04-21
On Apr 20, 5:29=A0pm, Lox <skolpojke...@yahoo.se> wrote:> Hello > > I=92m sampling a signal at 1000Hz rate. I need to find the derivative of > the signal every 100ms. > > I have tried to calculate it like this every 100ms: > > dx =3D (x_old =96 x) / 0.1 > x_old =3D x > > x is the signal at that moment. > > But I=92m thinking of how I could use the other 99 samples to get a > better approximation of the derivative over 100ms. > > If I could do a least square fit of a straight line of 100 samples and > take the slope of that line as the derivative. > > Any ideas?As Dilip sugested, try fitting a straight line to the data and finding its slope. If the data is uniformly sampled, then the linear regression becomes quite simple. Take a look at a paper I wrote a while back. http://www.claysturner.com/dsp/FIR_Regression.pdf Regards, Clay
Reply by ●April 21, 20112011-04-21
On Apr 20, 11:29=A0pm, Lox <skolpojke...@yahoo.se> wrote:> Hello > > I=92m sampling a signal at 1000Hz rate. I need to find the derivative of > the signal every 100ms. > > I have tried to calculate it like this every 100ms: > > dx =3D (x_old =96 x) / 0.1 > x_old =3D x > > x is the signal at that moment. > > But I=92m thinking of how I could use the other 99 samples to get a > better approximation of the derivative over 100ms. > > If I could do a least square fit of a straight line of 100 samples and > take the slope of that line as the derivative. > > Any ideas?Look up 'numerical differentiation'. This task is a standard task in numerical maths, and your choise of solution might get you into any sort of trouble, rangig from the hoplessly inaccurate result, to the ridiculously computationally expensive. Rune
Reply by ●April 21, 20112011-04-21
Hi Clay,>On Apr 20, 5:29=A0pm, Lox <skolpojke...@yahoo.se> wrote: >> Hello >> >> I=92m sampling a signal at 1000Hz rate. I need to find the derivativeof>> the signal every 100ms. >> >> I have tried to calculate it like this every 100ms: >> >> dx =3D (x_old =96 x) / 0.1 >> x_old =3D x >> >> x is the signal at that moment. >> >> But I=92m thinking of how I could use the other 99 samples to get a >> better approximation of the derivative over 100ms. >> >> If I could do a least square fit of a straight line of 100 samples and >> take the slope of that line as the derivative. >> >> Any ideas? > >As Dilip sugested, try fitting a straight line to the data and finding >its slope. If the data is uniformly sampled, then the linear >regression becomes quite simple. Take a look at a paper I wrote a >while back. > >http://www.claysturner.com/dsp/FIR_Regression.pdf > >Regards, >ClayThat's a nice, clearly reasoned, paper. I've done similar things, but I looked at what I was doing purely as a correlation with the pattern of interest (a straight line in this case). I'd never followed through to see that it works out exactly the same as a regression analysis. Steve
Reply by ●April 21, 20112011-04-21
On 21 Apr, 07:27, Clay <c...@claysturner.com> wrote:> On Apr 20, 5:29=A0pm, Lox <skolpojke...@yahoo.se> wrote: > > > > > > > > > > > Hello > > > I=92m sampling a signal at 1000Hz rate. I need to find the derivative o=f> > the signal every 100ms. > > > I have tried to calculate it like this every 100ms: > > > dx =3D (x_old =96 x) / 0.1 > > x_old =3D x > > > x is the signal at that moment. > > > But I=92m thinking of how I could use the other 99 samples to get a > > better approximation of the derivative over 100ms. > > > If I could do a least square fit of a straight line of 100 samples and > > take the slope of that line as the derivative. > > > Any ideas? > > As Dilip sugested, try fitting a straight line to the data and finding > its slope. If the data is uniformly sampled, then the linear > regression becomes quite simple. Take a look at a paper I wrote a > while back. > > http://www.claysturner.com/dsp/FIR_Regression.pdf > > Regards, > ClayThank you. It worked really well :-)
Reply by ●April 21, 20112011-04-21
On Apr 21, 12:27=A0am, Clay <c...@claysturner.com> wrote:> > As Dilip sugested, try fitting a straight line to the data and finding > its slope.I DID NOT suggest fitting a straight line to the samples; that was the OP's idea. He began by wanting to estimate the derivative of a signal at 100 ms intervals. He had samples of the signal taken at millisecond intervals. He then seemed to change his mind as to what he wanted and said that he wanted the derivative over the entire 100 ms interval. What does this mean? 100 values of the derivative at 1 millisecond intervals? or the average value of the 100 derivatives at 1 millisecond intervals? or simply using 100 samples to evaluate the derivative at one point? No useful answer can be given to the "question" being asked unless the question is stated more clearly and the OP follows Tim Wescott's advice to "Define what `better' means within the context of the larger problem that you're trying to solve." --Dilip Sarwate
Reply by ●April 21, 20112011-04-21
Lox schrieb:> Hello > > I�m sampling a signal at 1000Hz rate. I need to find the derivative of > the signal every 100ms. > > I have tried to calculate it like this every 100ms: > > dx = (x_old � x) / 0.1 > x_old = x > > x is the signal at that moment. > > But I�m thinking of how I could use the other 99 samples to get a > better approximation of the derivative over 100ms. > > If I could do a least square fit of a straight line of 100 samples and > take the slope of that line as the derivative. > > Any ideas?One idea would be to design a high pass filter which approximates the derivative (for example G(f)=abs(f)) and pass the signal through it. But you have to check the math before if this is appropriate for your task. Greetz, Sebastian
Reply by ●April 21, 20112011-04-21
On 4/20/2011 2:29 PM, Lox wrote:> Hello > > I�m sampling a signal at 1000Hz rate. I need to find the derivative of > the signal every 100ms. > > I have tried to calculate it like this every 100ms: > > dx = (x_old � x) / 0.1 > x_old = x > > x is the signal at that moment. > > But I�m thinking of how I could use the other 99 samples to get a > better approximation of the derivative over 100ms. > > If I could do a least square fit of a straight line of 100 samples and > take the slope of that line as the derivative. > > Any ideas?Nobody so far mentioned that "differentiation is a noisy process" .. a rule of thumb at the very least. Something to be aware of in system design involving differentiators. It appears that Clay's approach might help avoid some of this but I got hung up on "differentiation" vs. "slope determination" and don't have the guts or time today to wade through the math. I thought the comments about P-M differentiators in contrast were *very* interesting! How about it Clay? Some qualitative comments perhaps? er .. re "noisy"? Fred






