|On this page…|
You can use Simulink® software to model dynamic systems and simulate the behavior of your models. The basic techniques you use to create a simple model are the same techniques that you use for more complex models.
To create this simple model, you need four blocks:
Sine Wave — Generates an input signal for the model.
Integrator — Processes the input signal.
Mux — Combines the input signal and processed signal into one signal.
Scope — Visualizes the signals.
After you connect the blocks, simulating the model integrates a sine wave signal and displays the result, along with the original signal.
You can build this simple model yourself, starting with Create a New Model.
Before creating a model, you need to start MATLAB® and then start Simulink.
Start the Simulink software. In the MATLAB Command Window, enter:
The Simulink Library Browser opens.
From the Simulink Library Browser menu, select File > New > Model.
A Simulink Editor window opens with an empty canvas in the right-hand pane (the model window).
Select File > Save as. The Save As dialog box opens.
In the File name box, enter a name for your model. For example, enter simple_model. Then click Save.
Your model is saved with the file name simple_model.
To create a model, begin by copying blocks from the Simulink Library Browser to the Simulink Editor model window. For a description of the blocks in this example, see Overview of the Simple Model.
In the Simulink Library Browser, select the Sources library.
The Simulink Library Browser displays blocks from the Sources library in the right-hand pane.
Select the Sine Wave block.
Drag the Sine Wave block to the model window.
A copy of the Sine Wave block appears in your model.
Add the following blocks to your model, using the same approach that you used to add the Sine Wave block.
Your model now has the blocks you need for the simple model.
Before you connect the blocks in your model, you should arrange them logically to make the signal connections as straightforward as possible.
Move the Scope block after the Mux block output. To move a block in a model, use one of these approaches:
Click and drag the block.
Select the block, and then press the arrow keys on the keyboard.
Move the Sine Wave and Integrator blocks before the Mux block.
Your model should look similar to the following figure.
Your next task is to connect the blocks with signal lines.
After you add blocks to your model, you need to connect them. The connecting lines represent the signals within a model.
Most blocks have angle brackets on one or both sides. These angle brackets represent input and output ports:
The > symbol pointing into a block is an input port.
The > symbol pointing out of a block is an output port.
Connect the blocks by drawing lines between output ports and input ports. For information about how to add blocks to the model in this example, see Add Blocks to a Model.
Position the mouse pointer over the output port on the right side of the Sine Wave block.
The pointer changes to a cross hairs (+) shape while over the port.
Click and drag a line from the output port to the top input port of the Mux block.
While you hold the mouse button down, the connecting line appears as a red dotted arrow.
Release the mouse button over the output port.
Simulink connects the blocks with an arrow indicating the direction of signal flow.
Connect the output port of the Integrator block to the bottom input port on the Mux block:
Select the Integrator block.
Press and hold the Ctrl key.
Select the Mux block.
The Integrator block automatically connects to the Mux block with a signal line.
Connect the Mux block output port to the Scope block.
The simple model is almost complete, except for one connection. To finish the model, you need to connect the Sine Wave block to the Integrator block.
This final connection is different from the other three connections, which all connect output ports to input ports. Because the output port of the Sine Wave block is already connected, you must connect this existing line to the input port of the Integrator block. The new line, called a branch line, carries the same signal that passes from the Sine Wave block to the Mux block.
With the cursor at the end of the dotted red line, move the cursor so that it lines up with the light blue guide arrow that points in the direction of the Integrator input port. The cursor turns into a hollow arrow.
Drag the cursor to the Integrator input port and release the mouse button.
If necessary, smooth out the line segment that connects to the Integrator block. Select the unaligned line segment and drag it until the line is straight.
Your model diagram is now complete. Select File > Save.
After you finish building a model, you can simulate the dynamic behavior of the model. See Simulate the Simple Model.
Branched signals display a dot where the signals connect, as shown in Draw a Branch Line.
By default, straight signal lines that cross each other, but are not connected, display a slight gap before and after one of the intersecting lines.
Diagonal lines and Stateflow® chart curved lines do not display a gap.
To display solid unconnected crossing lines, enable Simulink Preferences > Editor Defaults > Use classic diagram theme.
Before you simulate a model, you have to set simulation options. Specify options, such as the stop time and solver, using the Model Configuration Parameters dialog box. For how to build the model in this example, see Create the Simple Model.
In the Simulink Editor, select Simulation > Model Configuration Parameters. The Configuration Parameters dialog box opens to the Solver pane.
In the Stop time field, enter 20. In the Max step size field, enter 0.2.
The Simulink software updates the parameter values with your changes and closes the Configuration Parameters dialog box.
After you enter your configuration parameter changes, you are ready to simulate the simple model and visualize the simulation results.
In the Simulink Editor, select Simulation > Run.
The simulation runs. The simulation stops when it reaches the stop time specified in the Configuration Parameters dialog box.
Double-click the Scope block.
The Scope window opens and displays the simulation results. The plot shows a sine wave signal with the resulting cosine wave signal from the Integrator block.
From the Scope block toolbar, click the Parameters button . Select the Style tab. The Scope Parameters dialog box displays figure editing options.
Change the appearance of the figure. For example, select white for the Figure color and Axes background color (icon with a pitcher) and black for the Ticks, labels and grid colors (icon with a paintbrush). Change the signal line colors for signal 1 to blue and for signal 2 to green. To see your changes, click OK.
The Simulink Editor closes with changes to your model and model configuration parameters.