# Simulating Range Bearing Sensor with MATLAB with Gaussian Noise (Generating Gaussian Colored Random Vector)

I would like to simulate a sensor that provides range and direction of a beacon. This is for EKF localization, so the noise must be Gaussian (i.e. $\mathcal{N}(0, \sigma^{2})$. Also, I would like to compute the measurement noise matrix $Q_{k}$ which is $$Q_{k} = \begin{bmatrix} \sigma^{2}_{r} & 0 \\ 0 & \sigma^{2}_{\theta} \end{bmatrix}$$

This is what I've done

sigma_range = 1;
sigma_angle = degtorad(5);
Q = [sigma_range^2,               0;
0, sigma_angle^2];


In the sensor, this is I've done

% add Gaussian noise with zero mean and some variance
Z(1) = Z(1) + sigma_range*randn(); % Z(1) the distance btw robot and beacon
Z(2) = Z(2) + sigma_angle*randn(); % Z(2) the angle btw robot and beacon


Is this correct?

## 1 Answer

Few notes:

1. First you should multiply the noise by the Standard Deviation (Root of the Variance for zero mean noise).
2. You can do that by multiplying the Lower Cholesky Decomposition of matrix by a column vector of Gaussian noise. Yet since you assume no correlation, you can do that by independent multiplication.

Something like:

vZ = vZ + [sigma_range; sigma_angle] .* randn([2, 1]);

• 1) I think I did. The standard deviation is sigma_range (i.e. $\sigma$) – CroCo Jun 16 '14 at 23:59
• I missed it at first sight I guess. You did well under the independent assumption. Otherwise, you should do it as I noted in my 2nd part. – Royi Jun 17 '14 at 12:56
• You can always check your answer by calculating a sample covariance matrix from you random observations. – David Jul 16 '14 at 12:54