Create a Simple Model

Model Overview for This Tutorial

You can use Simulink® to model a system and then simulate the dynamic behavior of that system. The basic techniques you use to create a simple model in this tutorial are the same techniques that you use for more complex models.

To create this simple model, you need four Simulink blocks:

  • Sine Wave — Generates an input signal for the model.

  • Integrator — Processes the input signal.

  • Bus Creator — Combines the input signal and processed signal into one signal.

  • Scope — Visualizes the signals.

Simulating this model integrates a sine wave signal to a cosine signal and then displays the result, along with the original signal, in a scope window.

Open the Simulink Library Browser

From the Simulink Library Browser, you can create a new model (block diagram) and search for blocks that you want to use in your model. You need MATLAB® running before you can open the Simulink Library Browser.

  1. From the MATLAB Toolstrip, click the Simulink Library button , or in the Command Window, enter

    simulink

    A short delay occurs the first time you open the Simulink Library Browser.

  2. Set the Library Browser to stay on top of the other desktop windows. On the Library Browser toolbar, select the Stay on top button .

Browse or Search for Specific Blocks

To browse through the block libraries, select a MathWorks® product and a functional area in the left pane. Alternatively, you can search all of the available block libraries at once.

  1. Search for a Sine Wave block. In the search box on the browser toolbar, enter sine, and then press the Enter key. Simulink searches the libraries for blocks with sine in their name, and then displays the blocks.

  2. Get detailed information about a block. Right-click a block, and then select Help for the <block name>. The Help browser opens with the reference page for the block.

  3. View block parameters. Right-click a block, and then select Block Parameters. The block parameters dialog box opens.

Open a New Model in the Simulink Editor

In the Simulink Editor, you can build and simulate models of your system. You need the Simulink Library Browser open before you can create a new Simulink model.

  1. From the Simulink Library Browser toolbar, click the New Model button . A Simulink Editor window opens with an new block diagram.

  2. Select File > Save as. In the File name text box, enter a name for your model. For example, enter simple_model, and then click Save.

    Simulink saves your model with the file name simple_model.slx.

Add Blocks to a Model

To build a model, begin by copying blocks from the Simulink Library Browser to the Simulink Editor.

  1. In the Simulink Library Browser, select the Sources library. The Library Browser displays the source blocks in the library.

  2. Select the Sine Wave block.

  3. Drag the Sine Wave block to the Simulink Editor. A copy of the Sine Wave block appears in your model.

  4. Add the following blocks to your model, using the same approach that you used to add the Sine Wave block.

    LibraryBlock
    SinksScope
    ContinuousIntegrator
    Signal RoutingBus Creator

    Your model now has the blocks you need for the simple model.

Move and Resize Blocks

Before you connect the blocks in your model, arrange them logically to make the signal connections as straightforward as possible.

  1. Move the Scope block after the Bus block output. You can either:

    • Click and drag a block.

    • Select the block, and then press the arrow keys on your keyboard.

  2. Move the Sine Wave and Integrator blocks before the Bus block.

    Move the blocks until your model looks similar to the following figure.

Simulink Block Connections

After you add blocks to your model, connect them with lines. The connecting lines represent the signals within your 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.

Draw Signal Lines Between Blocks

Connect the blocks by drawing lines between output ports and input ports.

  1. Position the cursor over the output port on the right side of the Sine Wave block.

    The pointer changes to a cross hair (+) while over the port.

  2. Click, and then drag a line from the output port to the top input port of the Bus block.

    While you are holding down the mouse button, the connecting line appears as a red dotted arrow.

  3. Release the mouse button when the pointer is over the output port.

    Simulink connects the blocks with a line and an arrow indicating the direction of signal flow.

  4. Connect the output port of the Integrator block to the bottom input port on the Bus Connector block using this alternative procedure:

    1. Select the Integrator block.

    2. Press and hold the Ctrl key.

    3. Click the Bus Connector block.

    The Integrator block connects to the Bus Connector block with a signal line.

      Note:   The Ctrl+click shortcut is useful when you are connecting widely separated blocks or when working with complex models.

  5. Connect the Bus Connector block to the Scope block by aligning ports:

    1. Click and drag the Scope block until its input port is aligned with the Bus Connector output port. A light blue line appears between the ports.

    2. Release the mouse button, and then click the blue line to create a black signal line.

Draw Branched Signal Lines

Your simple model is almost complete. To finish the model, connect the Sine Wave block to the Integrator block.

This connection is different from the other 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 Bus block.

  1. Hold down the Ctrl key.

  2. Position the cursor where you want to start a branch line. Click, and then drag the cursor away from the line to form a dotted-red line segment.

  3. Drag the cursor to the Integrator input port, and then release the mouse button.

  4. Drag line segments to straighten and align with blocks. Your model is now complete.

Define Simulation Parameters

Before you simulate the behavior of a model, define the simulation parameters. Simulation parameters include the type of numerical solver, start and stop times, and maximum step size.

  1. From the Simulink Editor menu, select Simulation > Model Configuration Parameters. The Configuration Parameters dialog box opens to the Solver pane.

  2. In the Stop time field, enter 20. In the Max step size field, enter 0.2.

  3. Click OK.

Run Simulation

After you define Model Configuration Parameters, you are ready to simulate your model.

  1. From the Simulink Editor menu bar, select Simulation > Run.

    The simulation runs, and then stops when it reaches the stop time specified in the Model Configuration Parameters dialog box.

      Tip   Alternatively, you can control a simulation by clicking the Run simulation button and Pause simulation button on the Simulink Editor toolbar.

Observe Simulation Results

After simulating a model you can view the simulation results in a Scope window.

  1. 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.

  2. From the Scope block toolbar, click the Parameters button . Select the Style tab. The Scope Parameters dialog box displays figure editing options.

  3. Change the appearance of the figure. For example, select white for the Figure color and Axes background color (icons with a pitcher).

  4. Select black for the Ticks, labels, and grid colors (icon with a paintbrush).

  5. Change the signal line colors for signal 1 to blue and for signal 2 to green. To see your changes, click OK.

Was this topic helpful?