electroSome

Introduction to Simulink in MATLAB

Contents

Simulink (Simulation and link) is developed by MathWorks as an add-on with MATLAB. It is a graphical programming language which offers modelling, simulation and analyzing of multi domain dynamic systems under Graphical User Interface (GUI) environment. The Simulink have tight integration with the MATLAB environment and have a comprehensive block libraries and toolboxes for linear and nonlinear analyses. The system models can be so easily constructed via just click and drag operations. The Simulink comes handy while dealing with control theory and model based design.

I recommend you to go through our MATLAB tutorials if you are a newbie in this.

This tutotial has been written for Simulink version 7.5 as my MATLAB version is R2010a

Getting Started

After the MATLAB is opened Simulink session can be started in 2 ways

>> simulink

A Simulink library window will pop up as shown below :

Simulink Library Browser

To start creating a model go to File –> New or alternatively Ctrl+N. A Work space / Model window will pop up as shown below :

Model window

This is the place where you work on with. Creating models and simulating it, all this will be done here. The user just have to click and drag appropriate blocks from the library browser on to the Work space/Model window.

Creating a Model

Here i’m going to create a simple model of integrating a sine wave and display both the input sine wave and the integral form. To create this model we need,

  1. A sine wave signal source
  2. Integrator
  3. A Multiplexer, as i need to display the 2 signals in the Display screen. Note that the display screen called ‘scope’ has only 1 channel. So either to show 2 signals we have to use a mux or we have to use 2 screen blocks
  4. A display screen

Charting down all the needed components is good practice when it comes to designing of higher models

STEP 1 : Selecting Blocks

Simulink –>Sources –> Select sine wave from the list

Simulink –>Continuous–>Select integrator from the block list

Simulink –>Signal routing –> Select Mux from the list

Simulink –>Sink –> Scope

Don’t worry if you don’t know where  your component is. There is a Search bar provided in the library browser where you can type your component and search for it.

STEP 2: Block Creation & Making Connections

Select and drag all components to the model window and make connections:

Sine Wave Integrator Model

NOTE:

STEP 3: Running Simulation

As the connections are made now your model is ready for running. Click on play button  in the model window. Alternatively Ctrl+T or Simulation –>Start in the model window can be used to run the simulation model.

To view the result double click on the Scope block which is our display screen.

OUTPUT :

Output

You can change the attributes of the axis by right click and specifying the axes properties. You can also auto scale the axes for a better view of the output.

Auto scaled Output

NOTE:

Simulation Control

Suppose if we want to control the simulation it can be managed by configuration parameters. Main parameters are start time, stop time, Solver type and methods.

For eg:  We can decide whether integration is to be  fixed step or variable step. If we are using Fixed Step we have to define the step size.

In the model window go to

Simulation–>Configuration Parameters. or alternatively press Ctrl+E.

Configuration Parameters window

STEP -4: Save the Model

To save the model

File –> Save As  which is in the tool bar of model window.

To use Out block

Simulink –>Sink –>Out

Model having Out ports

Now to see where our output gets stored and what variables are used open Configuration Parameters ( Ctrl+ E )

Go to Data Import/Export in it we can see there as time is stored as ‘tout’ and output stored as ‘yout’

Configuration Parameters ; Data Import / Export

Now if you want to know about the active variables (  tout and yout here ) you can use whos command in MATLAB workspace.

Now to plot the data in the workspace use plot commands.

plot(tout,yout);
xlabel('Time');
ylabel('Amplitude');
title('Model');
Work Space Output
Exit mobile version