# Numerical higher order derivatives and time axis

I have a rather elementary question. Suppose we wish to study even-derivatives of an instrumental signal say second fourth and sixth derivatives and plot it as a function of time. With each successive differentiation we lose the data points. If the initial number of data points were 1000, the second derivative will have 9998 points, the fourth derivative will have 9996 points and so on. This can be seen with the diff command in Matlab.

How should we align these derivatives with the time axis which has 1000 points for plotting purposes? The typical way is to leave the first two points of the time axis for the second derivative and first four points for the fourth derivative. Is there a mathematical justification for this way of alignment since a true derivative is defined at a point rather than this numerical approximation? In some chemistry texts, authors suggest to average the values of the x-axis and plot the derivatives with respect to that.

Thanks.

• How about padding your original input signal with required number of zeros and then performing the derivative task? Oct 16 '19 at 4:59
• As @Maxtron suggested I would also choose padding, however I would recommend to use the mirrored the signal. Oct 16 '19 at 5:59
• Lets us say our time series is t = [1, 2, 3, 4, 5, 6], and Signal= [y1, y2, y3, y4, y5, y6], should we zero pad for the second derivative as [0, 0, y1, y2, y3, y4, y5, y6] or do a mirror image of zeros, [0, 0, y1, y2, y3, y4, y5, y6,0,0] to keep number of elements the same as t? Oct 16 '19 at 12:54

When considering finite differences there are three of them: Forward, backward and central.

Neither of them is "shorter" than the main signal. The zero is not exactly zero, it should be $$\emptyset$$. That is, "I don't know".

In backward difference, $$y[n] = x[n] - x[n-1]$$, but at $$n=0$$, $$n-1$$ is not even defined and the same applies for $$y$$. We usually do $$y=0$$, (which implies that $$x[-1]=x$$).

Notice here that we wrote $$y[n]$$. In finite differences, in the discrete world, there is no $$x[0.5]$$. It is either $$0$$ or $$1$$. Central difference might appear to have a $$\frac{1}{2}n$$ term but that could be seen as a "phase shift" with respect to the sampling of the signal. The relative temporal difference between two successive samples is still one sampling period.

And this is the interesting bit here. The finite difference is the result of something that happens to two samples. Not one.

So, from the point of view of visualisation, you could show your first order finite difference as "occuring" between samples ($$+\frac{1}{2}Ts$$, where $$Ts$$ is the sampling period). The second order finite difference is something that "occurs" between pairs of samples of the first finite difference. The third order finite difference... (and so on).

Notice here that as you are working "up" the finite differences order, the starting point is "sliding" and the total length of the finite difference signal becomes shorter. The first order finite difference is between $$x[n],x[n+1]$$, the second order finite difference is between $$x'[n],x'[n+1]$$ which originate from $$(x[n], x[n+1])$$, $$(x[n+1], x[n+2])$$, the third order finite difference is between $$x''[n], x''[n+1]$$ which originate from $$(x, x)$$, $$(x,x)$$, $$(x,x)$$ and so on.

Notice here that throughout this nested evaluation of these finite differences that "I don't know" bit is becoming larger and larger. You cannot evaluate the $$y'''$$ of the third finite difference if you don't know the values of the first four samples of $$x[n]$$. But if you consider an "overlapping" segment across a part of the signal that is long enough to evaluate all finite differences, then you would be able to "see" all of them.

Hope this helps.

• Thanks for the details. I think main point is from the point of view of visualisation, you could show your first order finite difference as "occuring" between samples (+1/2Ts, where Ts is the sampling period). The second order finite difference is something that "occurs" between pairs of samples of the first finite difference. The third order finite difference... (and so on)." What would be mathematical justification for these t-coordinates? Oct 16 '19 at 15:28