# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

## Refine Existing Model

### Change Block Parameters

This example takes an existing model, `moving_car.slx`, and models a proximity sensor based on this motion model. In this scenario, a digital sensor measures the distance between the car an obstacle 10 m (30 ft) away. The model outputs the sensor measurement, and the position of the car, taking these conditions into consideration:

• The car comes to a hard stop when it reaches the obstacle.

• In the physical world, a sensor measures the distance imprecisely, causing random numerical errors.

• A digital sensor operates at fixed time intervals.

To start, open the `moving_car` model. In the MATLAB® Command Window, enter

```open_system(fullfile(matlabroot,... 'help', 'toolbox', 'simulink', 'examples', 'moving_car'))```

You first need to model the hard stop when the car position reaches `10`. The Integrator, Second Order block has a parameter for that purpose.

1. Double-click the Integrator, Second Order block. The Block Parameters dialog box appears.

2. Select Limit x and enter `10` for Upper limit x.

The background color for the parameter changes to indicate a modification that is not applied to the model.

3. Click to apply the changes and close the dialog box.

### Add New Blocks and Connections

Add a sensor that measures the distance from the obstacle.

1. Modify the model:

• Find the actual distance. To find the distance between the obstacle position and the vehicle position, add the Subtract block. Also add the Constant block to set the constant value of `10` for the position of the obstacle.

• To model the imperfect measurement that would be typical to a real sensor. Generate noise by using the Band-Limited White Noise block from the Sources library. Set the Noise power parameter to `0.001`. Add the noise to the measurement by using an Add block from the Math Operations library.

• The digital sensor fires every 0.1 seconds. In Simulink®, sampling of a signal at a given interval requires a zero order hold. Add the Zero-Order Hold block from the Discrete library. After you add the block to the model, change the Sample Time parameter to `0.1`.

• Add another Outport to connect to the sensor output.

2. Connect the new blocks. Note that the output of Integrator, Second-Order is already connected to another port. To create a branch in that signal, left-click the signal to highlight potential ports for connection, and click the appropriate port.

### Annotate signals

Add signal names to the model to make it easier to understand.

1. Double-click the signal. An editable textbox appears.

2. Type the signal name.

3. To finish, click away from the textbox.

4. Repeat these steps to add the names as shown.

### Compare Multiple Signals

Compare the Actual distance signal with the Measured distance signal.

1. Create and connect a new Viewer (Scope) to the Actual distance following Add Signal Viewer. Note that the name of the signal appears in the viewer title.

2. Add the Measured distance signal to the same viewer. Right-click the signal, and select Connect to Viewer > Scope1. Make sure you are connecting to the viewer you created in the previous step.

3. Run the model. The Viewer shows the two signals, Actual distance in yellow and Measured distance in blue.

4. Zoom into the graph to observe the effect of noise and sampling. Click the button . Left-click and drag a window around the region you want to see.

You can repeatedly zoom in to observe details.

From the plot, you can see that the measurement can deviate from the actual value by as much as 0.3 meters. This information becomes useful when designing a safety feature, for example, a collision warning.