Intro Simulink 2-Digital

36
Modelamiento de Sistemas Dinamicos  Dr. Jorge A. Olortegui Yume, Ph.D. I NTRODUCCI ON AL SI MULI NK  Dr . Jor g e A Ol orte gui Yu me , Esc uela Ac adem ico Pr ofesion al de I ngen ierf a Mec anica Universidad Privada Cesar Vallejo 1

Transcript of Intro Simulink 2-Digital

Page 1: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 1/36

Modelamiento de Sis temas Dinamicos 

Dr. Jorge A. Olortegui Yume, Ph.D.

I NTRODUCCI ON AL SI MULI NK

 Dr. Jorge A Olortegui Yume,

Escuela Academ ico Pr ofesion al de I ngen ier f a Mecanica

Univers idad Pr ivada Cesar Val le jo

1

Page 2: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 2/36

I NTRODUCCI ON AL SI MULI NK

LINEARMODELS

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, <Ph.<D.

Page 3: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 3/36

I NTRODUCCI ON AL SI MULI NK

E j G I T i p I O 1 I Sim uli nk Sol ut i on o f y = 10 sin t

Solucion 1:

i . Start Slmullnk and open a new mode] window as described previously.Select and p]ace In the new window the Sine Wave block from the Sources category. 

Double-click on it to open Lhe Block Parameters window, and make sure the Amplitude Is 

set to 1, the Bias to 0, the Frequency to I , the Phase to 0, and the Sample time to 0. Then 

click O K .

Select and place the Gain block from the Math category, double-click on It, and set the

Gain Value to 10 In the Block Parameters window. Then click OK. Note that the value 10

Lhen appears in the triangle. To make Lhe number more visible, click on the block, and drag

one of the corners to expand the block so that all the texL Is visible.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, <Ph.<D.

Page 4: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 4/36

I NTRODUCCI ON AL SI MULI NK 

Solucion 1 (cont) :

4. Select and place the Integrator block from the Continuous category, double- click on it Lo

obtain the Block Parameters window, and set the Initial Condition to 0 | this Is because

 y(0) —0]. Then click OK.5. Select and place the Scope block from the Sinks category.

<5. Once the blocks have been placed as shown In Figure 5.5.4, connect the input port on each

block to the oulport port on the preceding block. To do this, move the cursor to an Input

port or an output port; the cursor will change to a cross. Hold the mouse button down, and

drag the cursor to a port on another block. When you release the mouse button. Slmullnk 

 will connect them with an arrow pointing at the Input port. Your model should now look 

like that shown in Figure 5.5.4.7. Click on the Simulation itienurand click the Config uration Parameters item. Click on

the Solver tab. and enter 13 for the Stop time. Make sure the Start time Is 0. Then click OK.

S. Run the simulation by clicking on the Simulation menu, and then clicking the Start item.

 You can also start the s imulation by clicking on the S ta n icon on the toolbar (this is the

black triangle).

9. You will hear a bell sound when the simulation is finished. Then double- click on the Scope

block and then click on the binoculars Icon In the Scope display to enable autoscaling.

 You should see an oscillating curve with an amplitude of 10 and a period of 2jt. The

Independent variable in the Scope block is time t; the input to the block Is the dependent

variable y. This completes the simulation.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

Page 5: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 5/36

I NTRODUCCI ON AL SI MULI NK 

Solucion 1 (cont) :

Simulink Solution of y = 10 sir t

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, <Ph.<D.

Page 6: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 6/36

Ejemplo 2 : Expor t i ng to ths MA TLAB Work space

export the results of the simulation to the MATLAB workspace,

where they can be plotted or analyzed with any of the MATLAB functions,

I NTRODUCCI ON AL SI MULI NK

Solucion 2:Modify the Simultnk model constructed

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

Page 7: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 7/36

1. Delete the arrow connecting the Scope block by clicking on it and pressing the Delete key.

Delete the Scope block in the same way.

2. Select and place the To Workspace block from the Sinks category and the Clock block 

from the Sources category.3. Select and place the Mux block from the Signal Routing category, double- click on it, and

set the Number of inputs to 2. Click OK . (The name “Mux ” is an abbreviation for

“multiplexer,” which is an electrical device for transmitting several signals.)

4. Connect the top input port of the Mux block to the output port of the Integrator block. Then

use the same technique to connect the bottom input port of the Mux block to the outport

port of the Clock block. Your model should now look like that shown in Figure 5.4.5.

5. Double- click on the To Workspace block. You can specify any variable name you want as

the output; the default is s imout . Change its name to y. The output variable y will have

as many rows as there are simulation time steps, and as many columns as there are inputs

to the block. The second column in our simulation will be time, because of the way we

have connected the Clock to the second input port of the Mux. Specify the Save Format as

 Array. Use the default values for the other parameters (these should be in f , 1, and - 1 for

Max imum number of rows, Decimation, and Sample Time, respectively). Click on OK .6. After running the simulation, you can use the MAT LA B plotting commands from the

Command window to plot the columns of y (or s i mout in general). To plot y(t), type in

the MAT LAB Command window:

^ > p l o t ( y ( : , 2 ) , y ( : , 1 ) ) , x l a b e 1 { 1t 1) , y 1a b e 1( ' y 1)

I NTRODUCCI ON AL SI MULI NKSolucion 2:

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

Page 8: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 8/36

I NTRODUCCI ON AL SI MULI NK

Ejemplo 3 : Simulink Model for y = -  I Oy + f  (£)

Construct a Simulink model to solveV = - 1 0 y + f ( t ) v(0) = 1

 where  f { t ) = 2 sin At, for 0 < t < 3,

Solucion 3:■©

Sine Wave

Gain

1

s

Integrator Scope

< 1 0 1.

1* You can use Ihe model shown in Figure 5,4,4 by rearranging the blocks as shown in

Figure 5.4.6, You will need to add a Sum block.

2* Select the Sum bloc k fr om the Math operations librar y and place it as shown in thesimulation diagram. Its default setting adds two inpul s ignals. To change this, double- click 

on the block, and in the Lis t of Sig ns window, type | H— . The signs are ordered

counterclockwise from the top. The sy mbol | is a spacer indicating here that the top port

is to be empty.

I N TRO A SI M U LI N K  Dir. Jorge A OOrtegui Yume, Ph D

Page 9: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 9/36

I NTRODUCCI ON AL SI MULI NK

Solucion 3:

3. To reverse the direction of the gain block, right- click on the block, select Format from the

pop- up menu, and select Flip Block.4. When you connect the negative input port of the Sum block to the output port of Ihe Gain

block, Simulink will attempt to draw the shortest line. To obtain Ihe more standard

appearance shown in Figure 5,4,6, first extend the line vertically down from Ihe Sum input

port. Release the mouse button and then click on Ihe end of the line and attach it to the

Gain block. The result will be a line with a right angle. Do the same to connect the input of 

the Gain to the arrow connecting the Integrator and the Scope. A small dot appears toindicate that the lines have been successfully connected. This point is called a takeoff  point  because it takes the value of the variable represented by the arrow (here, the variable  y)  and makes that value available to another block.

5. Select Configuration Parameters from the Simulation menu, and set the Stop time to 3.

Then click  OK.6. Run the simulation as before and observe the results in the Scope.

I N TRO A SI M U LI N K  Dr. Jorge A . OlOrtegui Yume,

Page 10: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 10/36

I NTRODUCCI ON AL SI MULI NKEjemplo 4 : Simulink Model of a single mass system

m = 2 kg  c = 200 n.s/m k = 12 000 N/m

±(0) = 0.02 m ±(0) = 0m/s

I N TRO A SI M U LI N K  Dr. Jorge A . OlOrtegui Yume,

Page 11: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 11/36

I NTRODUCCI ON AL SI MULI NK 

Solucion 3:

I N TRO A SI M U LI N K  Dr. Jorge A . OlOrtegui Yume, Ph D

Page 12: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 12/36

I NTRODUCTI ON AL SI MULI NKEjemplo 5 I Simulink Model of a Two-Mass System

A two-mass system The equations of motion are

Put these equations into state- variable form.

The state-variable model of the two-mass system

Develop a Simulink model to plot the i mil -step response of the variables x\   and xz  with the

initial conditions .vi(0) = 0.2,.vi(0) = 0, ^̂ (0) = 0,5, and*2(0) = 0,

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

Page 13: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 13/36

Solucion 5:Using the system 's potential and kinetic energies as a guide, we see that the displacements x\ and

xz describe the system’s potential energy and that the velocities x i and xg describe the system's

kinetic energy. That is

P E = i f r ix\ + ^k2(x i - x2)2

This indicates that we need four state variables. (Another way to see that we need four variables

is to note that the model consists of two coupled second- order equations, and thus is effectively 

a fourth- order model.) Thust we can choose the state variables z\ ,zz, Z3 , and z\ to be

These definitions imply that z\ — 22 and Z3   — z\ , which are two of the state equations. The

remaining two equations can be found by solving equations (1) and (2) for x\ and x i, noting 

tliat x  1 = 7-i and xz = and using the substitutions given by equation (3).

I NTRODUCCI ON AL SI MULI NK

I N TRO A SI M U LI N K  Dr. Jorge A . OlOrtegui Yume, Ph.D

Page 14: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 14/36

I NTRODUCCI ON AL SI MULI NKSolucion 4:

Note that the left- hand sides of the state equations must contain only the first- order derivative

of each state variable. This is why we divided by 5 and 3, respectively. Note also that the right-

hand sides must not contain any derivatives of the state variables. For example, we should not use

the substitutionz\ for i i, but rather should substitute Z2 f o r ii . Failure to observe this restriction

is a common mistake.

Now list the four state equations in ascending order according to their left- hand sides, after

rearranging the right- hand sides so that the state variables appear In ascending order from left

to right.

Z\ = Z2 

z2 = ^ ( —5z i -  Y2zi + 4z3 + 8z4)□

Z2 — Z4 

 Z4 = ^[4zi + 8zz - 4Z3 - 8 Z4 + /(f)]

(4)

(5)

(6)

(7)

These are the state equations in standard form.

Note that because the potential energy Is a function of the difference x\ —xz, another

possible choice of state variables is zj = x\ ,zi = x\ , zs =  X[ —xz, and z\ —xi.

I N TRO A SI M U LI N K  Dr. Jorge A . OlOrtegui Yume, Ph.D.

Page 15: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 15/36

Ex press the state- variable model in vector- matrix form. The model is

i\ = ?!

z 2 =    7 (—5zi - 12z 2 + 4 z3 + 8z 4) j

Z3 — Z4

U  = 4- 8 z2 - 4 z3 - 8 z4 + /( f ) ]

In vector- matrix for m these e quations are

z = A z + B / ( 0

w h e r e

I NTRODUCCI ON AL SI MULI NKSolucion 4:

- 0 1 0 ( T " O '

- 112 

 — T

4

5

8

E 0

0 0 0 1B =

0

4 3 4 8 ]

_ 3 I “ 3 .  _ 3 _ 

a n d

*122 * i23 *2

_Z4. * zj

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

Page 16: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 16/36

I NTRODUCCI ON AL SI MULI NKSolucion 4:

First select appropriate values for the matrices in the output equation y = Cz — Df ( i ) . Since 

 we want to plot xj and which are z\ and z3 , we choose C and D as follows.

00

01

D

To create this simulation, obtain a new model window. Then do the following to create the 

model shown in Figure 5.4.7.

1.

2.

3.

4.

5.

Select and place in the new window the Step block from the sources category. Double-

click on it to obtain the Block Parameters window, and set the Step time to 0, the Initial 

and Final values to 0 and 1, and the Sample time to 0. Click OK .

Select and place the State Space block, Double click on it, and enter [ 0 , 1 , 0 , 0 ;

1 , 1 2 /5 , 4 / 5 , 8 / 5 ; 0 , 0 , 0 , 1; 4 /3 , 8 /3 , 4 /3 , 8 /3 ] for A ,

[ 0 ; 0; 0; 1/3] fbrB, [ I , 0„ 0 , 0; 0 , 0 , 1 f 0] for C, and [ 0 ; 0] for 

D, Then enter [ 0 . 2 ; 0 ; 0 . 5 ; 0 | for the initial conditions. Click OK . Note that the 

dimension of the matrix B tells Simulink that there is one input. The dimensions of the 

matrices C and D tell Simulink that there are two outputs.

Select and place the Scope block,

Once the blocks have been placed, connect the input port on each block to the out port port on the preceding block as shown in the figure,

Experiment with different values of the Stop time until the Scope shows that the steady  

state response has been reached. For this application, a Stop time of 25 is satisfactory, The 

plots of both x\ and x? will appear in the Scope,

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

Page 17: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 17/36

I NTRODUCCI ON AL SI MULI NKSolucion 4:

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

I NTRODUCCI ON AL SI MULI NK

Page 18: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 18/36

I NTRODUCCI ON AL SI MULI NK

NON-LINEARMODELS

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

I NTRODUCTI ON AL SI MULI NK

Page 19: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 19/36

I NTRODUCTI ON AL SI MULI NK Ejemplo 6 : Simulink Model of a Rocket-Propelled Sled

 A rocket- propelled sled on a track is represented in Figure 5,5.1 as a mass m with an applied

force / that represents the rocket thrust. The rocket thrust initially is horizontal, but the engine

accidentally pivots during firing and rotates with an angular acceleration of  0 = nj 50 rad/s.Compute the sled's velocity  v for 0 < t  < 10 if u{0) — 0, The rocket thrust is 4000 N and the

sled mass is 450 kg.

Figu re 5.5.1 A rocket- propelled sled.

a. Create a S imulink model to solve this problem for 0 < t  < 10 s.

b. Now suppose that the engine angle is limited by a mechanical stop to GO , which is

6(Lt / 180 rad. Create a Simulink model to solve the problem.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

I NTRODUCCI ON AL SI MULI NK

Page 20: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 20/36

I NTRODUCCI ON AL SI MULI NKSolucion 6:

450 £' = 4000 cos

Fresnel's cosine integral 

no closed-form solution is

available for the integral

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

I NTRODUCCI ON AL SI MULI NK

Page 21: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 21/36

I NTRODUCCI ON AL SI MULI NKSolucion 6:

Thus we can create 9(f) by integrating the constant 9 = tt/50 twice, The simulationdiagram is shown in Figure 5,5.2, T his diagram is used to create the corresponding 

Simulink model shown in Figure 5.5.3.

There are twro new blocks in this model. The Constant block is in the Sources library 

 After placing it, double click on it and type p i /5 0 in its Constant Value window.

The Trigonometric function block is In the Math Operations library: After placing it,

double click on it and select c o s in its Function window,

Set the Stop Time to 10. run the simulation, and examine the results In the Scope.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

I NTRODUCCI ON AL SI MULI NK

Page 22: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 22/36

b. Modify the model in Figure 5.5.3 as follows to obtain the model shown in Figure 5,5.4,

 We use the Saturation block in the Discontinuities library to limit the range of 9 to

GQtt/180 rad. After placing the block as shown in Figure 5.5,4, double- click on it and type

6 0 * p i /1 8 0 in its Upper Limit window. Then type 0 or any negative value in its Lowrer

Limit window.

Enter and connect the remaining elements as shown, and run the simulation. The

upper Constant block and Integrator block are used to generate the solution when the

engine angle is 9 = 0Has a check on our results. [The equation of motion for 9 = 0 isv = 80/9, which gives v(t) = 80//9.]

If you prefer, you can substitute a To Workspace block for the Scope, Then you can

plot the results in MAT LAB. The resulting plot is shown in Figure 5.5.5.

I NTRODUCCI ON AL SI MULI NKSolucion 6:

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

I NTRODUCTI ON AL SI MULI NK

Page 23: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 23/36

Solucion 6:I NTRODUCTI ON AL SI MULI NK

Simulation model for v = (80/9) cos (7Tt2/IOO)

d  l d  l e cos 8&

5 9 .

V  1 V 

5

Simulink model for v =

Simulink model for v  = (80/9) cos (ttt2/ 100) with a Saturation block.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

I NTRODUCTI ON AL SI MULI NK

Page 24: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 24/36

I NTRODUCTI ON AL SI MULI NK Ejemplo 7 : Simulink Model of a Nonlinear Pendulum

The pendulum shown in Figure 5.5.11 has the following nonlinear equation of motion, if there

is viscous friction in the pivot and if there is an applied moment  M( t) about the pivot.

10 + cO + mgL sin 6  =  M(t) (1)

 where  I  is the mass moment of inertia about the pivot. Create a Simulink model for this system

for the case where  I —4, mgL = 10, c = 0.8, and M(t) is a square wave with an amplitude of 3

and a frequency of 0.5 Hz. Assume that the initial conditions are 0(0) =tz /4rad and 0(0) = 0.

Figure 5 .5 .11  A pendulum.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

I NTRODUCCI ON AL SI MULI NK

Page 25: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 25/36

I NTRODUCCI ON AL SI MULI NKSolucion 7:

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

I NTRODUCCI ON AL SI MULI NK

Page 26: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 26/36

 We will introduce four new blocks to create Ihis simulation. Obtain a new model window and

do the following.

1+ Select and place in lhe new window the Integrator block from the Continuous category,and change its label to Integrator 1 as shown in Fig ure 5,5,12. Y ou can edit text

associated with a block by c licking on the text and making lhe changes. Double- click on

I NTRODUCCI ON AL SI MULI NKSolucion 7:

the block to obtain theBlock Parameters

window, and set the

Initial condition to 0

[this is the initial

condition f)(0) = 0 ].

Click OK.

Fen

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

I NTRODUCCI ON AL SI MULI NK

Page 27: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 27/36

Solucion I 2 . Copy the Integrator block to the location shown and change its label to Integrator 2. Set

its initial condition to 7r / 4 by typing p i /4 in the B lock Parameters window. T his is the

initial condition 0(0) = 7r /4 .

3. Select and place a Gain block from the Math Operations category, double- click on it, and

set the Gain value to 0.25. Click  OK . Change its label to 1 / 1. Then click on the block,

and drag one of the corners to expand the box so that all the text is visible.

4. Copy the Gain box, change its label to c, and place it as shown in Figure 5.5.12.

Double- click on it, and set the Gain value to 0.8. Clic k  OK . To flip the box left to

right, right- click on it, select Format, and select Flip Block.

5. Select and place the Scope block from the Sinks category.

6 . For the term 10 sin 9, we cannot use the Trig function block in the Math Operations

category without using a separate gain block to multiply the s in0 by  10 . Instead we will

use the Fen block under the User- Defined Functions category (Fen stands for function).

Select and place this bloc k as shown. Double- click on it, and type 10 * s i n (u) in the

expression window. This block uses the variable u to represent the input to the block.

Click  OK . Then flip the block.

7. Select and place the Sum block fr om the Math Operations category. Double- click on it,

and select round for the Icon shape. In the List of signs window, type H- - - - . Click  OK .

8 . Select and place the Signal Generator block from the Sources category. Double- click on

it, select square wave for the Wave form, 3 for the Amplitude , and 0.5 for the Frequency,

and Hertz for the Units. Click  OK .

9. Once the blocks have been placed, connect arrows as shown in the figure.

1 0 . Set the Stop time to 10, run the simulation, and ex amine the plot of 9(t) in the Scope.

This completes the simulation.

I NTRODUCCI ON AL SI MULI NK

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

I NTRODUCCI ON AL SI MULI NK

Page 28: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 28/36

I NTRODUCCI ON AL SI MULI NK

TRANSFERFUNCTIONS

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

I NTRODUCCI ON AL SI MULI NK

Page 29: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 29/36

Ej em plo 8 :Create and run a S imulink s imulation of a mass- spring- damper system (5.5.1) using the parameter

values m = 1 ,c = 2, and k —4. The forcing function is the function / (r) = sin 1.4/. The system

lias the dead- zone nonlinearity shown in Figure 5.5.6,

I NTRODUCCI ON AL SI MULI NK

F i g u r e

nonl inea

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

I NTRODUCCI ON AL SI MULI NK

Page 30: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 30/36

Solucion 8:Figure 5.5.7 The Simulink 

model of dead- zone response.

I NTRODUCCI ON AL SI MULI NK

To construct the simulation, do the following steps.

1. Start S imulink and open a new model w indow as described previously .

2. Se lect and place in the new window the Sine Wave block from the Sources category.Double- clic k on it: and set the A mplit ude to 1. the Bias to 0, the Fre quency to 1,4, the

Phase to 0, and the Sample time to 0. Click O K .

3. Se lect and place the Dead Zone block from the Discontinuities category, double- click on

it, and set the Start of dead zone to —0.5 a nd the End of dead zone to 0.5. Click O K .

4. Se lect and place the T ransfer Fen block from the Continuous category; double- click on it,

and set the Numer ator to [ 1 ] and the Denominator to | 1 , 2 , 4 ] . Click O K .5. Select and place the Scope block from the Sinks category.

6. Once the blocks have been placed, connect the input port on each block to the outport port

on the preceding block. Your model should now look like that shown in Figure 5.5.7.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

I NTRODUCCI ON AL SI MULI NK

Page 31: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 31/36

Solucion 8:Figure 5.5.7 The Simulink 

model of dead- zone response.

I NTRODUCCI ON AL SI MULI NK

7. Click on the Simulation menu, then click the Configuration Parameters item. Click on

the S olve r tab, and enter 10 for the S top time. Make sure the Start time is 0. T hen click O K .

8. Run the s imulation by clic king on the S imula tio n menu, and then click ing the S ta rt item.

9. Y ou w ill hear a bell sound when the simulation is finished* T hen double- click on the Scope

block and then click on the binoculars icon in the Scope display to enable autoscaling.

 Y ou s hould see an os cillating curve.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

I NTRODUCCI ON AL SI MULI NK

Page 32: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 32/36

I NTRODUCCI ON AL SI MULI NKSolucion 8:

Scope

It is informative to plot both the input and the output of the Transfer Fen block versus time

on the same graph. To do this,

1. Delete the arr ow connec ting the Scope block to the Transfer Fen block, E)o this by cl ick ing 

on the arrow line and then pressing the Delete key.

2. Select and place the Mux block fr om the Sig nal Routing category, clouble- click on it, and

set the Number o f inputs to 2. Click A pply , then OK .

3. Connec t the top input port of the Mux block to the output port of the Transfer Fen block.

Then use the s ame tec hnique to connect the bottom input port of the Mux block to thearrow from the outport port of the Dead Zone block. Just remember to start with the input

port. Simulink will sense the arrow automatically and make the connection. Your model

should now look like that shown in Figure 5.5.8.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

I NTRODUCCI ON AL SI MULI NK

Page 33: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 33/36

I NTRODUCCI ON AL SI MULI NKSolucion 8:

Figure 5.5.8 Modification of 

the dead-zone model to

include a Mux block.7 

 I 

Sine Wave Dead Zone

s 2+ 2s + 4

Transfer Fen

I- Scope

It is informative to plot both the input and the output of the Transfer Fen block versus time

on the same graph. To do this,

1. Delete the arrow connec ting the Sc ope block to the Transfer Fen block. E)othis by clicking 

on the arrow line and then pressing the Delete key.2. Select and place the Mux block from the Sig nal Routing category,double- click on it, and

set the Number o f inputs to 2. Clic k A pply , then OK .

3. Connec t the top input port of the Mux block to the output port of the T ransfer Fen block.

Then use the s ame technique to connect the bottom input port of the M ux block to the

arrow from the outport port of the Dead Zone block. Just remember to start with the input

port. S imulink w ill sense the arrow automatically and make the c onnection. Y our modelshould now look like that shown in Figure 5.5.8.

4. Set the Stop time to 10, run the simulation as before, and bring up the Scope display. You

should see what is shown in Figure 5.5.9. This plot shows the effect of the dead zone on

the sine wave.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

I NTRODUCCI ON AL SI MULI NK

Page 34: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 34/36

I NTRODUCCI ON AL SI MULI NKSolucion 8:

 Y ou can bring the s imula tio n results into the MA T L A B workspace by using the To Work space

block. For example, suppose we wrant to examine the effects of the dead zone by comparing the

response of the system with and without a dead zone. We can do this with the model shown in

Figure 5.5.10. To create this model,

1. Co py the T ransfer Fen block by right- clicking on it, holding dow n the mouse button, and

drag ging the block copy to a new loc ation. Then release the button. Copy the Mux block in

the same wray.

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph.D.

I NTRODUCCI ON AL SI MULI NK

Page 35: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 35/36

I NTRODUCCI ON AL SI MULI NKSolucion 8:

Figure 5.5.10 Modification of 

the dead-zone model to

export variables to the

MATLAB workspace.Sine Wave

//

Dead Zone

s2+2s+4

Transfer Fen 1

s2+2s+4

I n = n- - - I — T-- - - - -

- - - - " I - - - - -

Mux 1 Scope

Transfer Fen 2

Clock

Mux 2 To Workspace

2. Double- click on the first Mux block and change the number of its inputs to 3.

3. In the usual way, select and place the To Works pace block fr om the S inks category and the

Cloc k box from the Source s category. Double- click on the To Works pace block. Y ou can

specify any var iable name you w ant as the output; the def ault is s i mou t. Change its name

to y. The output variable y w ill have as many rows as there are s imulation time steps, and

as many columns as there are inputs to the block. The fourth column in our simulation will

be time, because of the way we have connected the Cloc k to the se cond Mux . S pecify the

save format as Array. Use the default values for the other parameters (these should be

i n f , 1, and - 1 for Max imum number of rows, Decimation, and S ample Time,

respectively). C lick on OK .

I N TRO A SI M U LI N K  Dr. Jorge A . Olortegui Yume, Ph D

I NTRODUCCI ON AL SI MULI NK

Page 36: Intro Simulink 2-Digital

7/29/2019 Intro Simulink 2-Digital

http://slidepdf.com/reader/full/intro-simulink-2-digital 36/36

I NTRODUCCI ON AL SI MULI NKSolucion 8:

4. Connect the blocks as shown, and run the s imulation.

5. Y ou can use the MA T L A B plotting commands fro m the Command w indow to plot the

columns of y; for example, to plot the response of the two systems and the output of the

Dead Zone block versus time, type

» p l o t ( y ( : , 4) , y ( : , 1) , y ( : , 4) , y ( : , 2) , y ( : , 4 ) , y (: , 3 ) )

I N TRO A SI M U LI N K D J A Ol t i Y Ph D