# Measurement model for Kalman filter but non-zero mean

I'm fusing two vision-based algorithms using the Kalman filter to estimate the state of a vehicle $X=(x,y,\theta)$ where $x$ and $y$ are the coordinates in the plan and $\theta$ the heading. The problem is with the matrix $R$ of the 2nd algorithm taken as the measurement model. $R$ refers to the noise covariance matrix$$R = \begin{bmatrix} \sigma_{x}^2 & 0 & 0 \\ 0 & \sigma_{y}^2 & 0 \\ 0 & 0 & \sigma_{\theta }^2 \\ \end{bmatrix}$$

In order to evaluate the variances, I tested the algorithm for example for the random variable $x$ and compared its retuned $x_{m}$ against the ground truth $x_{gt}$. Here is the histogram of $e(x)=\sqrt{{(x_{m}-x_{gt})}^2}$ in meters for $107$ measurements

The error is not zero-mean gaussian noise. For the gaussian shape is it correct to use maximum likelihood estimation to fit a gaussian to data, and how to deal with the non-zero mean issue? Is it possible to use non-zero mean noise for measurement with unscented kalman filter?

• Is this Kalman or Extended Kalman Filter? Also, the error should converge to zero. I don't understand what do you mean by the error is not zero-mean? – CroCo Dec 16 '17 at 2:55
• CroCo, the OP specified "unscented kalman filter" which is my personal favorite. However, the differences between standard, extended, and unscented are not really relevant to the problems discussed here. OP accidentally took the absolute value of a bunch of measurement errors expected their average to be 0. See my answer for analysis of how to fix this. – Eric Lavigne Dec 16 '17 at 20:11
• I'm working with two cases. In the first the measurement model is linear so I have to use the KF and it's non linear in the second so I'm intending to use the UKF. I faced the non zero-mean for both that's why I asked about the UKF too. – Daphnee Dec 17 '17 at 20:37

There are actually several issues in this question which I will answer separately.

1) Error is: $$\sqrt{(x_m-x_{gt})^2}$$

No, error is just $$(x_m - x_{gt})$$ This may be part of your problem with zero means because any error distribution will have a positive mean if you force all errors to be positive.

2) My error distribution does not have zero mean. How do I compensate for that?

Even after fixing that first issue, you may still have a non-zero mean. This can be fixed.

Determine the actual mean and use that to adjust any values that you receive from the sensor. This is called sensor calibration. So if you know that your sensor has a mean error of 8.3 and you receive a sensor measurement of 15, then you should treat that as a sensor measurement of 6.7 (15 - 8.3).

3) My error distribution is not gaussian. Is it okay to fit a gaussian to that distribution anyway?

Real error distributions are rarely gaussian, so fitting a gaussian is necessary. Unfortunately this does create a tradeoff for you to consider. If your gaussian is a good fit for the data in the 0-20 range then I think it will underestimate the probability of the outliers in the 30-50 range. That would cause your kalman filter to be overconfident and bounce around. Fitting a gaussian with larger sigma to include those values in the 30-50 range will result in smoother, but less precise output. The best result probably lies somewhere in between, so you'll need to experiment with that.

• $\sqrt{(x_m - x_{gt})^2} = (x_m - x_{gt})$?! – CroCo Dec 16 '17 at 2:48
• Real error distributions are rarely gaussian? Any references for this claim?! – CroCo Dec 16 '17 at 2:58
• Croco,he equality that you posted is only true when xm > xgt (because squaring will eliminate any minus signs and the sqrt operation will not bring that minus sign back. – Eric Lavigne Dec 16 '17 at 19:54
• My statement about real error distributions rarely being Gaussian was based on experience. The real reason that we so often treat them as Gaussians is that it makes the math easier (and it's often good enough). I tried typing "real error distributions are rarely gaussian" into Google and found an almost identical quote in page 292 of "Data Assimilation: Making Sense of Observations": "Error distributions for real observations are rarely precisely Gaussian. Real distributions often have significantly wider tails than can be expected from purely Gaussian statistics." – Eric Lavigne Dec 16 '17 at 20:07
• Regarding Gaussian noise modelling, I've read several books all the ones I've read mention the fact that Gaussian assumption works well in practice. – CroCo Dec 16 '17 at 20:17