DSPRelated.com
Forums
Online · Live + on demand
February 9-11, 2027
Price goes up Nov 1: register now to lock in today's rate
Register Now →

Calculate better derivative of an signal?

Started by Lox ●April 20, 2011
On Apr 21, 8:40=A0am, dvsarwate <dvsarw...@yahoo.com> wrote:
> 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. =A0He > began by wanting to estimate the derivative > of a signal at 100 ms intervals. =A0He had samples > of the signal taken at millisecond intervals. =A0He > then seemed to change his mind as to what he > wanted and said that he wanted the derivative > over the entire 100 ms interval. =A0What does this > mean? =A0100 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
True you did not suggest fitting the straight line. I should have phrased my statement better - sorry about that. I find often when one is asking questions, that he may have not completely framed his problem yet so I allow for a little latitude on the answer since the OP is still defining his problem. So our answers kind of shotgun around the OP's yet to be determined answer. This kind of reminds me of a friend when he needed to build something he would stare at his large collection of junk because it would get him to thiking about what he really needed. Clay
On Apr 21, 5:34=A0am, "steveu" <steveu@n_o_s_p_a_m.coppice.org> wrote:
> Hi Clay, > > > > > > > > >On Apr 20, 5:29=3DA0pm, Lox <skolpojke...@yahoo.se> wrote: > >> Hello > > >> I=3D92m sampling a signal at 1000Hz rate. I need to find the derivativ=
e
> of > >> the signal every 100ms. > > >> I have tried to calculate it like this every 100ms: > > >> dx =3D3D (x_old =3D96 x) / 0.1 > >> x_old =3D3D x > > >> x is the signal at that moment. > > >> But I=3D92m 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 > > That'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 se=
e
> that it works out exactly the same as a regression analysis. > > Steve- Hide quoted text - > > - Show quoted text -
Steve, Thanks, What put me on the path to this method was a problem where I was demodulating iDEN which uses four 16-QAM subcarriers FDMed together in a nearly 20kHz wide channel where the pilot codes were nonuniformly spaced. And with noise in my receiver, I was forced into a statisical approach. I later used the polarity method to achieve frame lock to the ghost cancellation reference signal in analog tv. It proved to be very quick and reliable. I thought it was kind of neat to combine correllation with regression. It leaves you feeling you are on the right track. Clay
On Apr 21, 11:50=A0am, Fred Marshall <fmarshallxremove_th...@acm.org>
wrote:
> On 4/20/2011 2:29 PM, Lox 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? > > Nobody so far mentioned that "differentiation is a noisy process" .. a > rule of thumb at the very least. =A0Something 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? =A0Some qualitative comments perhaps? =A0er .. re "noi=
sy"?
> > Fred- Hide quoted text - > > - Show quoted text -
Fred, In terms of qualitative answers, I've often found that low order differentiators often work better in practice since the high orders tend to magnify noise even more than the low order ones. High order processes often rely heavily on delicately balanced cancellations. And some processes will magnify the errors from such. Of course this is a rule of thumb and to be sure there will be exceptions. For example Lagrangian interpolation (polynomial fitting) in the classic straightforward implementation is fraught with numerical issues but the barycentric form uses ratios of differences so the errors tend to cancel. One of the comments I put into the article has to do with the coefs themselves. A high order polynomial or trigonometric differentiator tends to cluster most of its "energy" or computational work on the central coefs whereas the slope filter coefs tends to put more of the computational work away from the center. In terms of additive noise this seems to lower sensitivity because noise needs to have greater relative (to the signal) strength to affect the slope. I haven't spent much time doing any quantitative noise analysis on this approach. Maybe one day I'll revisit it. Clay
On 4/21/2011 9:40 AM, Clay wrote:
> On Apr 21, 11:50 am, Fred Marshall<fmarshallxremove_th...@acm.org> > wrote: >> On 4/20/2011 2:29 PM, Lox wrote: >> >> >> >> >> >>> Hello >> >>> I&#4294967295;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 &#4294967295; x) / 0.1 >>> x_old = x >> >>> x is the signal at that moment. >> >>> But I&#4294967295;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- Hide quoted text - >> >> - Show quoted text - > > Fred, > > In terms of qualitative answers, I've often found that low order > differentiators often work better in practice since the high orders > tend to magnify noise even more than the low order ones. High order > processes often rely heavily on delicately balanced cancellations. And > some processes will magnify the errors from such. Of course this is a > rule of thumb and to be sure there will be exceptions. For example > Lagrangian interpolation (polynomial fitting) in the classic > straightforward implementation is fraught with numerical issues but > the barycentric form uses ratios of differences so the errors tend to > cancel. One of the comments I put into the article has to do with the > coefs themselves. A high order polynomial or trigonometric > differentiator tends to cluster most of its "energy" or computational > work on the central coefs whereas the slope filter coefs tends to put > more of the computational work away from the center. In terms of > additive noise this seems to lower sensitivity because noise needs to > have greater relative (to the signal) strength to affect the slope. I > haven't spent much time doing any quantitative noise analysis on this > approach. Maybe one day I'll revisit it. > > Clay
Thanks Clay, I'm sure this will be helpful to folks interested in this. I had noticed the comment about the coefs. Fred
On 04/20/2011 05:29 PM, Lox wrote:
> Hello > > I&#4294967295;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 &#4294967295; x) / 0.1 > x_old = x > > x is the signal at that moment. > > But I&#4294967295;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?
The analytical, discrete-time derivative has impulse response h[n] = cos(n*pi) / n [proakis] This filter is non-causal and infinite. However, by truncating to a finite number of terms and introducing a delay, a causal FIR version can be derived. @BOOK{proakis, title = "{Digital Signal Processing: Principles, Algorithms, and Applications}", author = "John~G.~Proakis and Dimitris~G.~Manolakis", publisher = "Prentice Hall", edition = "third", year = "1996"} -- Randy Yates % "So now it's getting late, Digital Signal Labs % and those who hesitate mailto://yates@ieee.org % got no one..." http://www.digitalsignallabs.com % 'Waterfall', *Face The Music*, ELO
On Apr 26, 4:05&#4294967295;am, Randy Yates <ya...@ieee.org> wrote:
> On 04/20/2011 05:29 PM, Lox wrote: > > > > > > > Hello > > > I&#4294967295;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 &#4294967295; x) / 0.1 > > x_old = x > > > x is the signal at that moment. > > > But I&#4294967295;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? > > The analytical, discrete-time derivative has impulse response > > &#4294967295; &#4294967295;h[n] = cos(n*pi) / n &#4294967295; &#4294967295; &#4294967295;[proakis] > > This filter is non-causal and infinite. However, by truncating to a > finite number of terms and introducing a delay, a causal FIR version > can be derived.
Picking nits: The statement "*a* causal FIR version" might be interpreted to indicate that the problem has exactly one solution. It does not. As I indicated a few days ago, the ideal differentiator can be approxmated in any number of ways, depending on constraints and requirements. Rune

Randy Yates wrote:


> The analytical, discrete-time derivative has impulse response > > h[n] = cos(n*pi) / n [proakis]
But this is simply wrong. How about the signal x(n) = n ? Vladimir Vassilevsky DSP and Mixed Signal Design Consultant http://www.abvolt.com
On 4/25/2011 7:44 PM, Vladimir Vassilevsky wrote:
> > > Randy Yates wrote: > > >> The analytical, discrete-time derivative has impulse response >> >> h[n] = cos(n*pi) / n [proakis] > > But this is simply wrong. > > How about the signal x(n) = n ? > > > Vladimir Vassilevsky > DSP and Mixed Signal Design Consultant > http://www.abvolt.com
How about "the analytical, discrete-time differencer has impulse response...... " ? 'cause a "derivative" isn't a system but a differentiator or a differencer is. And, the signal and the system are independent so apply x(n)=n to it .. fine. No? Fred

Fred Marshall wrote:
> On 4/25/2011 7:44 PM, Vladimir Vassilevsky wrote: > >> >> >> Randy Yates wrote: >> >> >>> The analytical, discrete-time derivative has impulse response >>> >>> h[n] = cos(n*pi) / n [proakis] >> >> >> But this is simply wrong. >> >> How about the signal x(n) = n ? >> > > How about "the analytical, discrete-time differencer has impulse > response...... " ? > 'cause a "derivative" isn't a system but a differentiator or a > differencer is. And, the signal and the system are independent so apply > x(n)=n to it .. fine. No?
No. VLV
On 04/25/2011 10:44 PM, Vladimir Vassilevsky wrote:
> > > Randy Yates wrote: > > >> The analytical, discrete-time derivative has impulse response >> >> h[n] = cos(n*pi) / n [proakis] > > But this is simply wrong. > > How about the signal x(n) = n ?
Ha! Good point (again) Vlad! I tried analyzing this and got a series that doesn't converge. -- Randy Yates % "So now it's getting late, Digital Signal Labs % and those who hesitate mailto://yates@ieee.org % got no one..." http://www.digitalsignallabs.com % 'Waterfall', *Face The Music*, ELO