This is really simple. First of all, you need to understand how the sensor works. In other words, you need understand whether the measurements is coming from linear or nonlinear model. Second, what is the type of the sensor's noise?
CASE STUDY:
Let's say you want to simulate DC Voltemeter to measure a battery's voltage of 5 Volt. In an ideal case, the model of the system is
$$
V_{b}(k+1) = V_{b}(k)
$$
It is just a constant value whether you measure it now or in the future, the value is 5 Volt. In the reality, this is not the case. If you measure it now, you might get 4.9 Volt, later on 5.1 Volt. The measurements vary which means the sensor is noisy. In many cases, the noise is Gaussian with zero mean and some variance (i.e. $\mathcal{N}(0, \sigma^{2}))$. Therefore, the measurement model is
$$
Z(k+1) = V_{b}(k+1) + \delta
$$
where $\delta$ is the measurement noise (i.e. $\mathcal{N}(0, \sigma^{2})$).
To simulate this scenario in Matlab,
clear all; clc;
ideal_value = 5;
sigma = 0.01;
real_value = ideal_value + sigma*randn(5,1)
The output is then
real_value =
5.0009
5.0173
4.9939
4.9926
4.9825
In reality, there is no way to know the ideal value. If you want to decrease the accuracy of your sensor, you need to increase the value of the $\sigma$. In 2D laser scenario, the input of the sensor is the Cartesian location ($x, y$) and the output is the polar coordinates ($r, \phi$) with some Gaussian noise. Let's say we have a 2D laser sensor that is located in the origin and we have a tree in planar environment. The sensor with update rate 10 Hz provides the range $r$ and the bearing $\phi$ to the tree with some noise in both the range and the bearing. Therefore the following code simulates the scenario
clear all
clc
tree_x = 4;
tree_y = 4;
sigma_r = 0.1; % m
sigma_p = deg2rad(1); % rad
dt = 1/10;
t = 0:dt:0.5;
for i = 1:numel(t)
r(i) = sqrt( tree_x^2 + tree_y^2 ) + sigma_r*randn();
p(i) = atan2( tree_y, tree_x ) + sigma_p*randn();
end
r
rad2deg(p)
The results are
r =
5.7598 5.7581 5.6356 5.5525 5.6130 5.7552
p =
44.6549 45.6293 44.1343 44.7299 44.5913 44.7023