1

I'm trying to differentiate experimental data which are measured with time. However, the time increments are not equally spaced.

I first obtained a trend line for these data and then did a linear interpolation to obtain equally spaced points. Then I used central differencing to obtain the derivative. However, this gives a derivative that is not smooth and has steps in it. How can I solve this problem?

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467
  • 1
    How about using some smoother? I guess it depends on what you want to do with the derivative, though... – Stijn Apr 23 '13 at 07:27
  • I was thinking of smoothing the derivative. But I don't understand why this happens. Because the trend line I plotted is smooth but the derivative isn't. Note that when I say it isn't smooth, I'm plotting the derivative with time and this plot isn't smooth. – lost.identity Apr 23 '13 at 07:50
  • What do you mean with "trend line"? – Stijn Apr 23 '13 at 08:00
  • The experimental data I have is discrete points from two different experimental runs. Using matlab I obtained a polynomial fit through these points, which I called the trend line. – lost.identity Apr 23 '13 at 08:03
  • Why don't you just differentiate the polynomial you fit to your data? – Stijn Apr 23 '13 at 08:27
  • The polynomial that I get is not equally spaced either. I know that you can numerically differentiate unequally spaced data, but I've not tried that before. That's why I used linear interpolation to obtain equally spaced points. – lost.identity Apr 23 '13 at 08:30
  • 1
    "Equally spaced" does not apply to polynomials: polynomial functions are always defined for all real (and even Complex) numbers. If you indeed did fit a polynomial with Matlab, then its derivative will be smooth: it cannot possibly "have steps in it." It sounds like either you fit something else (such as a polynomial spline) or you have made a computational error. Please edit your post to clarify. – whuber Sep 03 '18 at 13:26

1 Answers1

0

Better than first fitting a nonlinear function somehow and then computing its derivative, you should consider doing both at once. One solution is using splines, a cubic spline will have a continuous first derivative (which can be calculated analytically from the fit).

But, there are many sorts of splines, interpolating splines, smoothing splines, regression splines, so which to choose? See the answer to The Pros and Cons of Smoothing spline for some details.

kjetil b halvorsen
  • 63,378
  • 26
  • 142
  • 467