I am trying to find the one-dimensional velocity of a car based on position measurements, similar to the Wikipedia article. The car moves at almost constant speed and I am mostly interested in getting smooth velocity estimates.
My problem is that while the sensor usually gives good values, sometimes there are strong outliers where the position makes huge jumps from close to the true value and back. Or the measured position stays constant (even though the car is moving at constant speed) and after say 5 values the measured position jumps back near the true value.
As I am new to velocity estimation and Kalman filters, I have made a first implementation according to $$\hat{\dot{x}}_{k} = \hat{\dot{x}}_{k-1} (1 - \alpha) + \alpha \frac{z_k - z_{k-1}}{\Delta t}$$ hoping to understand the problem better. $\hat{\dot{x}}$ is the estimate of the velocity and $z$ is the measured position. This already gives decent results except that the effect of the outliers is too strong. I was therefore thinking about trying to remove outliers from the input, e.g. by selecting the median of a sequence of positions.
Question: Do you think this is a useful approach? How should I try to get rid of unrealistic values?
Update: I tried a standard Kalman filter with state vector $(x, y, \dot{x}, \dot{y})^T$. I set the covariance matrix of the process noise $\mathbf{Q}$ to be due to random uncorrelated accelerations in $x$ and $y$ of equal magnitude and the covariance matrix of the measurement noise $\mathbf{R}$ to be diagonal. I tested different values of the parameters and found the results to be quite impressive. The state vector without accelerations $\ddot{x}$ and $\ddot{y}$ even worked better than with accelerations. So it seems that I do not even need an additional median filter. Unfortunately, I cannot share any measurements.
Addendum: Thanks for the help. So if I understand correctly, each correction step is only done when, for a state vector of $(x, \dot{x})^T$, $ \vert x_{k, pred} - z_k \vert < \sqrt{{p_{1 1}}_{k, pred}} \frac{2}{3}$ is true?
The original problem may look like this (position over time):
What if the data set looks like the following? Is there a way to deal with this behavior?