Non-standard five-point formula for second derivative used in Tracker

approximationcalculusderivativesnumerical methods

Tracker is an open-source program used to analyze object trajectories from video. The typical data sets Tracker produces are time series of object positions at various times, i.e., data pairs (t_i,x_i) for $i=1$ to $N$. The time samples are assumed to have uniform time step $t_{i}-t_{i-1}=\Delta t$. Tracker then uses this data to generates estimates for the first and second derivatives, corresponding to the velocity $v=dx/dt$ and acceleration $a=d^2x/dt^2$ respectively. By default, it does this using the following finite difference schemes:

$$v_i = \frac{x_{i+1}-x_{i-1}}{\Delta t},\qquad a_i = \frac{1}{7(\Delta t)^2}(2x_{i+2} – x_{i+1} – 2x_i – x_{i-1} + 2x_{i-2}) $$

The first is a standard two-point formula which requires no comment. However, the standard 5-point formula for the second derivative is

$$f''(x)\approx \frac{-f(x+2h)+16 f(x+h)-30 f(x)+16f(x-h)-f(x-2h)}{12h^2} \tag{1}$$
which has error of order $O(h^4)$. (Note that this formula is exact for quartic polynomials but not quintic.) The formula used by Tracker, by contrast, would correspond to $$f''(x)\approx \frac{2f(x+2h)- f(x+h)-2 f(x)-f(x-h)+2f(x-2h)}{12h^2}. \tag{2}$$ Both sides do match in the limit $h\to 0$, but the error is instead $O(h^2)$. So Tracker uses a scheme which, on the face of it, is not as precise.

Tracker's documentation doesn't address this point in detail, but does state the following: "Note: there are many other finite difference algorithms. Tracker's algorithms define the velocity for a step to
be the average velocity over a 2-step interval, and the acceleration to be the second derivative of a parabolic fit over a 4-step interval, with the step at the center. Tracker's acceleration algorithm is less sensitive to position uncertainties than others." The last sentence is especially notable. So my question as a whole is: What's the precise motivation behind Tracker's use of approximation (2), and in what sense (if any) is it "less sensitive to position uncertainties?"

Best Answer

Let's try and fit a parabola $$ x_i=c_0+c_1t_i+c_2t_i^2+\varepsilon_i $$ and WLOG assume $\Delta t=1$ and $t_0=0$ for easier calculation. Using ordinary least square regression (i.e., minimizing $\sum\varepsilon_i^2$), we need to solve the system \begin{align*} 5 c_0 + 10 c_2 &=\sum_{i=-2}^2 x_i\\ 10 c_1 &=\sum_{i=-2}^2 ix_i\\ 10 c_0 + 34 c_2 &=\sum_{i=-2}^2 i^2x_i \end{align*} i.e., $$ \begin{pmatrix} c_0\\c_1\\c_2 \end{pmatrix} = \begin{pmatrix} \dots\\ \frac1{10}\sum_{i=-2}^2 ix_i\\ \frac1{14}\sum_{i=-2}^2 (i^2-2)x_i \end{pmatrix} $$ and the acceleration being $2c_2$ by the usual 'suvat' equations. This gives the formula for $a$ as the Tracker doc claims.

Curiously, note that the velocity estimate $c_1$ is different here. If we kept the two-point estimate of velocity in our fit, it would deliver a different estimate for acceleration.


Edit: After thinking more about it, "less sensitive to position uncertainties" could also mean the individual coefficients are smallest possible: $\lVert\alpha\rVert=\max_i\lvert\alpha_i\rvert$ is smallest over all $a=\sum_i \alpha_i x_i$ while still accurate for the case of uniform acceleration (so the error of a single reading contributes as little as possible). Clearly we only need to consider $\alpha_i=\alpha_{-i}$ (otherwise we take the average of $\alpha$ and its reverse yielding something with no larger $\lVert\cdot\rVert$). So $\alpha$ is an affine combination of $(\frac14,0,-\frac12,0,\frac14)$ and $(0,1,-2,1,0)$ \begin{align*} \alpha&=(\frac14,0,-\frac12,0,\frac14)\lambda + (0,1,-2,1,0)(1-\lambda)\\ &=(\frac14\lambda,1-\lambda,\frac32\lambda-2,1-\lambda,\frac14\lambda) \end{align*} and so we must be either $\pm\frac14\lambda=1-\lambda$, $\pm\frac14\lambda=\frac32\lambda-2$ or $\pm(1-\lambda)=\frac32\lambda-2$ and it is easy to check these cases.