Sei sulla pagina 1di 10

2.

INTRODUCTION TO SIMULINK

2.1 What is SIMULINK?

SIMULINK is a program with graphical programming facilities for simulating


dynamic systems.

As an extension to MATLAB, SIMULINK adds many features specific to dynamic


systems while retaining of MATLAB’s general purpose functionality. For example
complex systems containing also nonlinearities can be built and analysed easily.

A short introduction is given here. For more details we refer to the help function and
the SIMULINK documentation.

SIMULINK has two phases of use, model definition and model analysis. First a
model has to be defined or a previously defined model is recalled. Then that model is
analysed.

To facilitate model definition SIMULINK adds a new class of windows called block
diagram windows. In these windows models are created and edited by mouse driven
commands.

After having defined a model, we can analyze it either by choosing options from the
SIMULINK menus or by entering commands in MATLAB’s command window. The
progress of a simulation can be viewed while the simulation is running, and the final
results can be made available in MATLAB workspace when a simulation is complete.

2.2 Constructing a model

SIMULINK represents dynamic systems with block diagrams. Defining a system is


much like drawing a block diagram. Instead of drawing the individual blocks, blocks
are copied from libraries of blocks, either the standard block library supplied with
SIMULINK or block libraries you build yourself.

The standard block library is organized into several subsystems, grouping blocks
according to their behavior. Blocks can be copied from these or any other libraries or
models into your model.

First, double-click on the SIMULINK icon to invoke MATLAB. Then, open the
SIMULINK block library by entering the command “ simulink ”. This command
displays a new window containing icons for the subsystem blocks (Fig.2.1).

1
Fig. 2.1 Simulink block library

Constructing your model select New from the File menu to open a new empty
window in which you can build your model.

Open one or more libraries and drag some blocks into your active window.

The subsystem libraries can be opened by double clicking providing their blocks to be
copied into your model. The Sources library, for example, contains blocks creating
input signals (Fig. 2.2).

Fig. 2.2 Sources library

Fig. 2.3 shows the most commonly used blocks collected in the Extras sublibrary.

Using the blocks of the libraries different systems, e.g. continuous or discrete control
systems can be built and analysed.

2
To build your model you can drag the appropriate blocks by the left mouse button
from their libraries to your file to the required position where you release the button.
To connect two blocks use the left mouse button to click on either the output or input
port of one block, drag to the other block's input or output port to draw a connecting
line, and then release the button. By clicking on the block with the right button you
can duplicate it. The blocks can be increased, decreased, rotated. Open the blocks by
double clicking to change some of their internal parameters. Save the system by
selecting Save from the File menu. Run a simulation by selecting Start from the
Simulation menu. Simulation parameters can be changed. You can monitor the
behavior of your system with a Scope or a Graph block or you can use the To
Workspace block to send data to the MATLAB workspace and perform MATLAB
functions (e.g. plot) on the results.

.
Fig. 2.3 The most commonly used blocks

Some useful remarks:

After having selected the block can be rotated in the Style and Options menu points.
The measure of the block can be changed by catching and moving its corner.
A part of the block diagram consisting of several blocks can be condensed into a
single one block from the Options menu with point Group.

3
Example 1

Fig. 2.4 illustrates the SIMULINK diagram of a continuous control system. The
blocks have been dragged from the Sources, Linear, Nonlinear and Sinks libraries
respectively. The input signal is a unit-step starting at t=1. The simulation time was
50, the simulation step 0.1. Runge-Kutta integration algorithm was chosen from the
Simulation menu. Fig. 2.5 and 2.6 shows the course of the output signals as displayed
in the Graph windows. Both of the output signals transported to MATLAB
workspaces can also be plotted by MATLAB plot(t,x1) and plot(t,y) command. It is
seen, that the y output signal tracks the reference input signal without steady-state
error due to its integrating characteristics. The deadtime causes the 5 seconds delay
between the changing of the output and the input signal. The x1 control signal on the
plot shows an overshoot, which has a maximum value of 1.5. The minimum and
maximum value of the output signal can be determined by matlab: min(y)=0,
max(y)=1.041.

Fig. 2.4 Simulink block-diagram of a control system

Fig. 2.5 The control signal Fig. 2.6 The output signal

4
Example 2
Investigating the effect of saturation

Fig. 2.7 Nonlinear system with saturation

Fig. 2.8a The effect of saturation on the Fig. 2.8b The control signal with
output signal saturation at S=5 and S=100

Fig. 2.7 gives an overview on the effect of the saturation. This model shows the
saturating characteristics of the physically realizable controllers. The input signal is a
unit step starting at t=1. If the controller saturates at 5, so the output signal will react
slower because of the limited control signal (Fig. 2.8a and 2.8b). We can make the
model more compact by grouping the parts of the controller into one subsystem(Fig.
2.9). We can do this by selecting the components with mouse and grouping them with
the group command from the options menu.

Fig. 2.9

5
2.3 Levels of use

There are three different ways to use SIMULINK, the most interactive way is to
control the simulation from the menu bar, and to view the behavior of the system with
the Scopes or Graphs. This method is simple to use, quick to learn, and can provide
fast results.

The second way is to use the built-in simulation and analysis function from the
command line. This method is not as interactive as the first method but provides
greater flexibility. Getting the results of simulation into the MATLAB workspace
allows further analysis and data visualization using MATLAB’s built-in graphics
tools.

The most complex and flexible way to use SIMULINK is to access a model’s S-
function directly. Every SIMULINK model is available in MATLAB as an S-function
that embodies the dynamical behavior of the system.

Simulation of SIMULINK models involves the numerical integration of sets of


ordinary differential equations. SIMULINK provides a number of integration
algorithms for the simulation of such equations. The appropriate choice of method
and the careful selection of simulation parameters are important considerations for
obtaining accurate results. A simulation can be started from either the command line
or the simulation menu. All of the methods use the same arguments and menu
parameters.

Simulation from the Menu

A simulation can be run by selecting Start from the Simulation menu. Set the
simulation parameters in the control panel dialog box, which is displayed by selecting
Parameters from the Simulation menu. The Control Panel dialog box has fields in
which you can enter numbers or any legal MATLAB expression, for example, the
variables tstart, tfinal, minstep, maxstep, and final which can be defined in the
MATLAB workspace. The return variables [t,x,y] are used to put the time, state, and
output trajectories into MATLAB workspace. The start and stop times for the
simulation are set in variables tstart and tfinal. The integration parameters final,
minstep and maxstep control the relative local error, minimum step size, and
maximum step size of the simulation. Certain operations can be performed
interactively during the simulation. For example the parameters of a block can be
changed provided this does not cause a change in the number of states, inputs or
outputs of that block; any of the simulation parameters can be changed , except return
variables and the start time; the simulation algorithm can be changed; for discrete
blocks you can change the sampling time.

You can click on a line to see its output on a floating scope. An unconnected scope is
called a floating scope.

6
Simulation from the Command Line

Any simulation run from the menu can also be run from the MATLAB command line.
For example

[t,x,y]=linsim('model',[tstart,tfinal],x0,[final,minstep,maxstep]);

where model is the name of the block diagram system. Initial conditions are defined in
the vector x0. These conditions override the initial conditions set in the blocks.

Specifying no lefthand arguments automatically plots the outputs or the state


trajectories.

A simulation can be run from an m-file allowing parameters in the blocks to be


iteratively changed.

All of the integration algorithms have identical calling syntax (e.g. instead of linsim
euler, rk23, rk45, adams or gear respectively).

Viewing output trajectories

The output trajectories from SIMULINK can be plotted by Scope or Graph blocks, or
by return variables and the MATLAB plotting commands, or by To Workspace
blocks and MATLAB plotting commands.

2.4 Changing parameters of SIMULINK blocks from MATLAB

“set_param” is used to set SIMULINK block parameters from the MATLAB


command line. Its syntax is

set_param(name, parameter, value)


or set_param(name, parameter, value,parameter2,value2…)

Specific block parameters vary with each type of block. The names and effects of
each block’s specific parameters can be found in the entry for that block.

Example 3

The Simulink block diagram of a control system is show in Fig 2.10. The system
saved with the name ‘dtime’.

7
Fig. 2.10 Simulink block-diagram of ‘dtime’ system

Following MATLAB program shows how to change the controller denominator from
the MATLAB window:

for i=4:2:10
den=[i 0];
%we set the controller’s integrating time constant
%to different values (1/4s...1/10s)
set_param('dtime/controller','Denominator','den');
%sets dtime system, controller part, Denominator value to den
[t,x,y]=rk23('dtime',50);
%50 sec simulation for each denominator value
yaux=x(:,2);
%2nd column of x gives the output signal
plot(t,yaux),grid
hold on
shg
pause
end

Fig. 2.11

8
Example 4
Changing the gain and the damping factor in a second order system

Fig. 2.12 Simulink diagram of a second order system

The gain and the damping factor of the second order system shown in Fig. 2.12
changes. The program changes te gain to 1, 2 and 3 respectively while the damping
factor is 0.2 and plots the output signals in the same diagram(Fig. 2.13)

The system is stable, but an oscillating transient is present in the outputs due to the
small value of the damping factor. If we increase the damping factor, the output signal
becomes aperiodic. The second part of the MATLAB program shows the output
signal at different values of the damping factor(Fig. 2.14).

for i=1:3
G=i;
set_param('setpar/Gain','Gain','G');
set_param('setpar/Transfer Fcn','Denominator','[1 0.4 1]');
% Change the gain
[t,x]=linsim('setpar',30);
% Integration algorithm for simulation, final time=30
y=x(:,2);
% The output is the second state variable

for j=1:(length(t))
yy(j,i)=y(j);
end
end
plot(t,yy,'w'),grid
pause

% Change the damping factor


G=1;
[t1,x]=linsim('setpar',30);
y1=x(:,2);
set_param('setpar/Transfer Fcn','Denominator','[1 4 1]');
[t2,x]=linsim('setpar',30);
y2=x(:,2);
plot(t1,y1,'w',t2,y2,'w'),grid

9
Fig. 2.13 Changing the gain Fig. 2.14 Changing the damping factor

10

Potrebbero piacerti anche