# Computation of normalized first derivative in discrete case

I am reading a paper on recognition of online handwritten characters. One of the features proposed in the paper is "normalized first derivatives, $(\hat{x}'_t,\hat{y}'_t)$", which they have defined as follows:

$$\hat{x}'_t=\frac{x'_t}{\sqrt{(x'_t)^2+(y'_t)^2}}\quad\quad \hat{y}'_t=\frac{y'_t}{\sqrt{(x'_t)^2+(y'_t)^2}}\,,$$ where

$$x'_t=\frac{\sum_{i=1}^2i(x_{t+i}-x_{t-i})}{2\sum_{i=1}^{2}i^2}\quad\quad y'_t=\frac{\sum_{i=1}^2i(y_{t+i}-y_{t-i})}{2\sum_{i=1}^{2}i^2}$$ I have couple of doubts with respect to these definitions:

1. If the derivatives are to be normalized, what is the significance of the denominators in the definition of $x'_t$ and $y'_t$?

2. Why is the difference scaled by $i$ in the numerator? What I understand is that this scaling gives more weight to the points farther from the central point.

For the first part of your question, the significance is just to guarantee that the vector $(\hat{x}'_t,\hat{y}'_t)$ has length $1$. This means that it tells us in which direction $(x_t,y_t)$ is changing, but not by how much. For example, $(\hat{x}'_t,\hat{y}'_t)=(1,0)$ tells us that $x_t$ is increasing and $y_t$ is constant; $(\hat{x}'_t,\hat{y}'_t) = (-\sqrt{2}/2, \sqrt{2}/2)$ tells us that $x_t$ is decreasing, and $y_t$ is increasing at the same rate.

The second part isn't something I know about, so I'll leave that for somebody else.

As you have noticed, the denominators in the definition of $x'_t,y'_t$ ultimately have no effect, as they will be normalized away.

Nonetheless, they do have significance. This definition ensures that $x'_t,y'_t$ represent the derivatives. If you omitted the denominators in the definition of $x'_t,y'_t$, you'd get the same value for $\hat{x}'_t,\hat{x}'_t$, but the expression for $x'_t,y'_t$ would look less familiar and $x'_t,y'_t$ would no longer correspond to the derivatives (they would be some scaled version of the derivative), so it might be harder for some readers to see what's going on.

In other words, think of this explanation as optimized for ease of understanding for readers. There are often many ways to describe something, and hopefully we choose the one that's easiest on our readers.

I don't know why the authors scaled the difference by $i$. It doesn't have any advantage that I can see. The expression given there approximates the first derivative, up to an error term of third order, which is better than the simpler expression $x'_t = (x_{t+1}-x_{t-1})/2$... but the same would be true even if the difference wasn't scaled by $i$, so that can't be the explanation. You might need to ask the authors. It appears that an even better approximation would be

$$x'_t = -\frac{1}{12} x_{t+2} + \frac{2}{3} x_{t+1} - \frac{2}{3} x_{t-1} + \frac{1}{12} x_{t-2}$$

and similarly for $y'_t$. This approximation is accurate up to a fourth-order term, which is better than the one in your question. See https://en.wikipedia.org/wiki/Finite_difference_coefficient.

You are given a stroke passing through points: $(x_{t-2}, y_{t-2}), (x_{t-1}, y_{t-1}),(x_{t}, y_{t}), (x_{t+1}, y_{t+1}), (x_{t+2}, y_{t+2})$. You fit a straight line to these points, to obtain $x'_t$ and $y'_t$ ($dx$ and $dy$), and then normalize these vectors.

It looks like a regression formula computing $x'_t$ and $y'_t$, but I am not sure how it is derived. The following picture may give you idea. The middle point on $X$-axis is $(x_t, y_t)$.

If the derivatives are to be normalized, what is the significance of the denominators in the definition of $x'_t$ and $y'_t$?

The denominators are used to normalize the vector $(x'_t,y'_t)$, to convert $(x'_t,y'_t)$ to the unit vector providing the direction of the vector does not change. Please look here for significance of normalization. You should check references of the paper how these formulas are derived.