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} &amp; 0 \\ 0 &amp; \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?
Few notes:


First you should multiply the noise by the Standard Deviation (Root of the Variance for zero mean noise).
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]);