I get position information and a corresponding timestamp from a motion tracking system (for a rigid body) at 120 Hz. The position is in sub-millimeter precision, but I'm not too sure about the time stamp, I can get it as floating point number in seconds from the motion tracking software. To get the velocity, I use the difference between two samples divided by the $\Delta t$ of the two samples:

$\dot{\mathbf{x}} = \dfrac{\mathbf{x}[k] - \mathbf{x}[k-1]}{t[k]-t[k-1]}$.

The result looks fine, but a bit noisy at times. A realized that I get much smoother results when I choose the differentiation step $h$ larger, e.g. $h=10$:

$\dot{\mathbf{x}} = \dfrac{\mathbf{x}[k] - \mathbf{x}[k-h]}{t[k]-t[k-h]}$.

On the other hand, peaks in the velocity signal begin to fade if I choose $h$ too large. Unfortunately, I didn't figure out why I get a smoother signal with a bigger step $h$. Does someone have a hint? Is there a general rule which differentiation step size is optimal with respect to smoothness vs. "accuracy"?

This is a sample plot of one velocity component (blue: step size 1, red: step size 10):

Sample plot of step size 1 vs. step size 10.

  • 1
    $\begingroup$ The step size in your case is t = 1/120 = 0.008333 sec. Estimating derivatives of experimental data is not trivial task. Decreasing the step size h randomly can have catastrophic results. You will get more details at Signal Processing Stack overflow. $\endgroup$ – CroCo May 3 '16 at 9:22

This answer valid only if $\Delta{t} = \mathbf{t}[k] - \mathbf{t}[k-1]$ is a constant. Then you can rewrite your equation as: $$\dot{\mathbf{x}} = \dfrac{\mathbf{x}[k] - \mathbf{x}[k-1]}{\Delta{t}}$$


$$ \dot{\mathbf{x}}_l = \dfrac{1}{h}\sum_{i=1}^{h}\dot{\mathbf{x}_i} = \dfrac{(\mathbf{x}[k] - \mathbf{x}[k-1])+(\mathbf{x}[k-1] - \mathbf{x}[k-2])+\dotsb+(\mathbf{x}[k-h+1] - \mathbf{x}[k-h])}{h\Delta{t}} = \bigg(\dfrac{\mathbf{x}[k] - \mathbf{x}[k-h]}{h\Delta{t}}\bigg) $$

$$ h\Delta{t} = \mathbf{t}[k] - \mathbf{t}[k-h] $$

Here $\dot{\mathbf{x}}_i$ is the $i^{th}$ sample of the reading and passing it through a moving average filter (which is a low pass filter) you can obtain $\dot{\mathbf{x}_l}$. So $\dot{\mathbf{x}_l}$ is smooth as it is a low pass signal. When you increase the value of $h$ you can minimize the bandwidth of $\dot{\mathbf{x}_l}$. So when you increase the value of $h$ the result is getting more smoother. So peaks begin to fade(Peaks means high frequency components).

As I know there isn't a generalize way to determine $h$ to get the result smoother and accurate. You have to choose appropriate $h$ by a trial and error or if you know the transfer function of the sensor, you can use that to determine an appropriate value for $h$.

| improve this answer | |
  • $\begingroup$ Thanks, I was looking for this kind of answer. Actually, $\Delta t$ isn't truly constant, but it doesn't play a role. I didn't realize it simply results in a moving average filter when increasing the step size. In this case, I will prefer to choose a step size of 1 and apply LP filtering later. $\endgroup$ – donald May 4 '16 at 5:47
  • 1
    $\begingroup$ Yeah, I would also prefer that.. $\endgroup$ – Ramesh-X May 4 '16 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.