+ All Categories
Home > Documents > Introduction to Simulink

Introduction to Simulink

Date post: 30-Oct-2015
Category:
Upload: aaron-vergara
View: 146 times
Download: 1 times
Share this document with a friend
Description:
Introduction to Simulink
Popular Tags:

of 66

Transcript
  • IntroCop

    Ta1

    2

    3

    4

    5duction to Simulink with Engineering Applications, Third Edition i

    ble of ContentsIntroduction to Simulink .................................................................................................11

    1.1 Simulink and its Relation to MATLAB .....................................................................111.2 Modeling an Electric Circuit ......................................................................................111.3 Modeling a FourthOrder Differential Equation....................................................1141.4 Modeling the Solution of Three Equations with Three Unknowns .......................1181.5 Representing a Model as a Subsystem ......................................................................1201.6 Simulink Demos .......................................................................................................120

    Mathematical Applications.............................................................................................21

    2.1 Bouncing Ball..............................................................................................................212.2 Linear Programming ...................................................................................................232.3 Moving Ladder ..........................................................................................................2102.4 Conical Water Reservoir........................................................................................... 2122.5 Comparison of Alternate Proposals.......................................................................... 2152.6 Valuation of a Depleting Asset .................................................................................219

    Dynamics Applications ....................................................................................................31

    3.1 An Application of Newtons Second Law ................................................................... 3-13.2 Ball Thrown Vertically Upward................................................................................... 3-33.3 Barge Pulled by Horse Teams ...................................................................................... 3-83.4 Rated Speed of an Automobile on a Highway Curve ...............................................3-103.5 Train Traveling on a 3 Per Cent Grade.....................................................................3-123.6 Spring with Upper End Fastened to a Rigid Support ...............................................3-17

    Thermodynamics and Fluid Mechanics Applications...................................................41

    4.1 Rise of a Liquid in a Capillary Tube ..........................................................................414.2 An Application of a Simplified Form of the Bernoulli Equation..............................434.3 Takeoff Speed for an Aircraft .....................................................................................444.4 An Application of the Bulk Modulus.........................................................................464.5 Calculation of Fluid Flow in an Open Channel ...................................................... l47

    Assortment of Math and Engineering Applications......................................................51

    5.1 Chemical Solutions ....................................................................................................515.2 Heat Flow....................................................................................................................535.3 Cantilever Beam Deflection ......................................................................................5 45.4 Tractrix Curve Example .............................................................................................565.5 Bessel Differential Equation ......................................................................................585.6 Van der Pol Differential Equation .............................................................................59yright Orchard Publications

  • ii

    5.7 Simple Pendulum..................................................................................................... 511

    5.8 Simple Oscillator...................................................................................................... 5135.9 ZeroOrder Hold and FirstOrder Hold as Reconstructors .................................. 5145.10 Direct Form Realizations of a Digital Filter ........................................................... 5165.11 Series Form Realization of a Digital Filter ............................................................. 5185.12 Parallel Form Realization of a Digital Filter........................................................... 5205.13 3bit Up / Down Counter..................................................................................... 5235.14 4bit Ring Counter ................................................................................................ 5245.15 MassSpring-Dashpot ............................................................................................. 5255.16 Cascaded MassSpring System............................................................................... 5285.17 Mechanical Accelerometer...................................................................................... 5295.18 Feedback Control Systems...................................................................................... 5305.19 Electric Circuit in Phasor Form ............................................................................. 5325.20 Application of the Superposition Principle ........................................................... 5345.21 Discrete Time Integration with Variable Amplitude Input ................................... 5375.22 SFunction Example 1 ........................................................................................... 5395.23 SFunction Example 2 ........................................................................................... 5415.24 Concluding Remarks .............................................................................................. 544Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCop

    ApA

    B

    Cduction to Simulink with Engineering Applications, Third Edition iii

    pendixesIntroduction to MATLAB .......................................................................................... A1

    A.1 MATLAB and Simulink..................................................................................... A1A.2 Command Window.................................................................................................. A1A.3 Roots of Polynomials................................................................................................ A3A.4 Polynomial Construction from Known Roots......................................................... A4A.5 Evaluation of a Polynomial at Specified Values....................................................... A5A.6 Rational Polynomials................................................................................................ A7A.7 Using MATLAB to Make Plots ................................................................................. A9A.8 Subplots .................................................................................................................. A16A.9 Multiplication, Division, and Exponentiation....................................................... A17A.10 Script and Function Files ...................................................................................... A25A.11 Display Formats ..................................................................................................... A29

    Masked Subsystems ......................................................................................................... B1

    B.1 Masks Defined .......................................................................................................... B1B.2 Advantages Using Masked Subsystems..................................................................... B1B.3 Mask Features ........................................................................................................... B1B.4 Creating a Masked Subsystem .................................................................................. B2

    Commonly Used .............................................................................................................. C1

    C.1 Inport, Outport, and Subsystem.............................................................................. C1C.2 Ground..................................................................................................................... C4C.3 Terminator ............................................................................................................... C6C.4 Constant and Product.............................................................................................. C7C.5 Scope ........................................................................................................................ C9C.6 Bus Creator and Bus Selector ................................................................................ C10C.7 Mux and Demux .................................................................................................... C18C.8 Switch ..................................................................................................................... C21C.9 Sum......................................................................................................................... C23C10 Gain........................................................................................................................ C25C.11 Relational Operator .............................................................................................. C26C.12 Logical Operator ................................................................................................... C27C.13 Saturation.............................................................................................................. C28C.14 Integrator............................................................................................................... C30C.15 Unit Delay ............................................................................................................. C35C.16 DiscreteTime Integrator...................................................................................... C37C.17 Data Types and Data Type Conversion................................................................ C40C.18 Vector Concatenate .............................................................................................. C49yright Orchard Publications

  • iv

    D

    E

    FContinuousTime ........................................................................................................... D1

    D.1 Derivative ................................................................................................................. D1D.2 Integrator.................................................................................................................. D6D.3 Integrator Limited.................................................................................................... D6D.4 Integrator Second Order.......................................................................................... D8D.5 Integrator Second Order Limited.......................................................................... D11D.6 PID Controller ....................................................................................................... D12D.7 PID Controller (2DOF) ......................................................................................... D14D.8 StateSpace ............................................................................................................ D19D.9 Transfer Fcn ........................................................................................................... D22D.10 ZeroPole .............................................................................................................. D25D.11 Transport Delay, Variable Time Delay, Variable Transport Delay ...................... D29

    Discontinuities .................................................................................................................E1

    E.1 Saturation................................................................................................................... E1E.2 Saturation Dynamic ................................................................................................... E4E.3 Dead Zone.................................................................................................................. E5E.4 Dead Zone Dynamic .................................................................................................. E6E.5 Rate Limiter ............................................................................................................... E8E.6 Rate Limiter Dynamic.............................................................................................. E10E.7 Backlash.................................................................................................................... E11E.8 Relay ......................................................................................................................... E13E.9 Quantizer.................................................................................................................. E15E.10 Hit Crossing ............................................................................................................ E16E.11 Coulomb and Viscous Friction .............................................................................. E18E.12 Wrap to Zero........................................................................................................... E19E.13 Nonlinear Systems Describing Functions ........................................................... E20

    Discrete ............................................................................................................................. F1

    F.1 Unit Delay ................................................................................................................. F1F.2 Integer Delay ............................................................................................................. F1F.3 Tapped Delay ............................................................................................................ F3F.4 Discrete Time Integrator........................................................................................... F4F.5 Discrete Transfer Fcn Block ..................................................................................... F5F.6 Discrete Filter............................................................................................................ F8F.7 Discrete ZeroPole .................................................................................................. F10F.8 Difference................................................................................................................ F11F.9 Discrete Derivative .................................................................................................. F12F.10 Discrete StateSpace.............................................................................................. F13F.11 Transfer Fcn First Order........................................................................................ F16Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCop

    F.12 Transfer Fcn Lead or Lag .......................................................................................F17

    G

    Hduction to Simulink with Engineering Applications, Third Edition v

    F.13 Transfer Fcn Real Zero ...........................................................................................F20F.14 Discrete FIR Filter ..................................................................................................F21F.15 Memory...................................................................................................................F24F.16 FirstOrder Hold ...................................................................................................F25F.17 ZeroOrder Hold ...................................................................................................F26F.18 Discrete PID Controller .........................................................................................F26F.19 Discrete PID Controller (2DOF) ...........................................................................F28

    Logic and Bit Operations ...............................................................................................G1

    G.1 Logical Operator ......................................................................................................G1G.2 Relational Operator ..................................................................................................G1G.3 Interval Test .............................................................................................................G2G.4 Interval Test Dynamic .............................................................................................G3G.5 Combinatorial Logic................................................................................................G4G.6 Compare to Zero......................................................................................................G6G.7 Compare to Constant..............................................................................................G7G.8 Bit Set.......................................................................................................................G8G.9 Bit Clear...................................................................................................................G8G.10 Bitwise Operator .....................................................................................................G9G.11 Shift Arithmetic ....................................................................................................G11G.12 Extract Bits............................................................................................................G12G.13 Detect Increase......................................................................................................G13G.14 Detect Decrease ....................................................................................................G14G.15 Detect Change ......................................................................................................G14G.16 Detect Rise Positive ..............................................................................................G15G.17 Detect Rise Nonnegative ......................................................................................G16G.18 Detect Fall Negative..............................................................................................G17G.19 Detect Fall Nonpositive ........................................................................................G18

    Lookup Tables ................................................................................................................. H1

    H.1 Lookup Table.......................................................................................................... H1H.2 Lookup Table (2D) ............................................................................................... H4H.3 Lookup Table (nD).............................................................................................. H 5H.4 Prelookup................................................................................................................ H8H.5 Interpolation (nD) Using PreLookup .................................................................. H9H.6 Direct Lookup Table (nD).................................................................................. H10H.7 Lookup Table Dynamic ........................................................................................ H15H.8 Sine and Cosine.................................................................................................... H16H.9 Function Lookup Table Generation .................................................................... H18yright Orchard Publications

  • vi

    I Math Operations .............................................................................................................. I1I.1 Sum ............................................................................................................................. I1I.2 Add ............................................................................................................................. I1I.3 Subtract ....................................................................................................................... I2I.4 Sum of Elements......................................................................................................... I3I.5 Bias.............................................................................................................................. I3I.6 Weighted Sample Time Math .................................................................................... I4I.7 Gain ............................................................................................................................ I5I.8 Slider Gain.................................................................................................................. I5I.9 Product........................................................................................................................ I6I.10 Divide......................................................................................................................... I6I.11 Product of Elements .................................................................................................. I7I.12 Dot Product ............................................................................................................... I8I.13 Sign ............................................................................................................................ I9I.14 Abs ........................................................................................................................... I10I.15 Unary Minus............................................................................................................ I10I.16 Math Function......................................................................................................... I11I.17 Rounding Function ................................................................................................. I12I.18 Polynomial ............................................................................................................... I13I.19 MinMax.................................................................................................................... I14I.20 MinMax Running Resettable .................................................................................. I15I.21 Trigonometric Function .......................................................................................... I16I.22 Sine Wave Function ................................................................................................ I17I.23 Algebraic Constraint................................................................................................ I18I.24 Assignment .............................................................................................................. I19I.25 Reshape.................................................................................................................... I20I.26 Squeeze..................................................................................................................... I20I.27 Matrix Concatenate ................................................................................................. I22I.28 Permute Dimensions ............................................................................................... I23I.29 Complex to MagnitudeAngle................................................................................ I23I.30 MagnitudeAngle to Complex................................................................................ I24I.31 Complex to RealImag............................................................................................ I25I.32 RealImag to Complex............................................................................................ I26I.33 Sqrt........................................................................................................................... I27I.34 Signed Sqrt............................................................................................................... I28I.35 Reciprocal Sqrt ........................................................................................................ I29I.36 Find Nonzero Elements........................................................................................... I30I.37 Vector Concatenate ................................................................................................. I33Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCop

    J

    K

    Lduction to Simulink with Engineering Applications, Third Edition vii

    Model Verification ........................................................................................................... J1

    J.1 Check Static Lower Bound .........................................................................................J1J.2 Check Static Upper Bound.........................................................................................J2J.3 Check Static Range .....................................................................................................J2J.4 Check Static Gap.........................................................................................................J3J.5 Check Dynamic Lower Bound....................................................................................J4J.6 Check Dynamic Upper Bound ...................................................................................J5J.7 Check Dynamic Range................................................................................................J6J.8 Check Dynamic Gap ...................................................................................................J7J.9 Assertion......................................................................................................................J8J.10 Check Discrete Gradient............................................................................................J9J.11 Check Input Resolution...........................................................................................J10

    ModelWide Utilities ..................................................................................................... K1

    K.1 TriggerBased Linearization .................................................................................... K1K.2 TimeBased Linearization........................................................................................ K3K.3 Model Info................................................................................................................ K6K.4 Doc Text ................................................................................................................... K8K.5 Block Support Table................................................................................................. K8

    Ports & Subsystems ...........................................................................................................L1

    L.1 Inport, Outport, and Subsystem .............................................................................. L1L.2 Trigger....................................................................................................................... L1L.3 Enable (description).................................................................................................. L1L.4 FunctionCall Generator......................................................................................... L2L.5 Atomic Subsystem .................................................................................................... L3L.6 Virtual and Nonvirtual Subsystems.......................................................................... L7L.7 Code Reuse Subsystem............................................................................................. L7L.8 Enable (added to subsystem block)......................................................................... L11L.9 Model ...................................................................................................................... L16L.10 Configurable Subsystem ........................................................................................ L17L.11 Triggered Subsystem.............................................................................................. L23L.12 Enabled Subsystem ................................................................................................ L26L.13 Enabled and Triggered Subsystem ........................................................................ L28L.14 FunctionCall Subsystem...................................................................................... L32L.15 For Iterator Subsystem........................................................................................... L35L.16 While Iterator Subsystem ...................................................................................... L36L.17 If and If Action Subsystem .................................................................................... L38L.18 Switch Case and Switch Case Action Subsystem.................................................. L40L.19 Model Variants ...................................................................................................... L42yright Orchard Publications

  • viii

    L.20 Variant Subsystem..................................................................................................L49

    M

    NL.21 For Each Subsystem ...............................................................................................L52L.22 FunctionCall Split ...............................................................................................L57L.23 FunctionCall Feedback Latch..............................................................................L58L.24 Subsystem Examples ..............................................................................................L59L.25 SFunction.............................................................................................................L62

    Signal Attributes .............................................................................................................M1

    M.1 Data Type Conversion............................................................................................M1M.2 Data Type Duplicate...............................................................................................M4M.3 Data Type Propagation...........................................................................................M6M.4 Data Type Scaling Strip ..........................................................................................M7M.5 Data Conversion Inherited ....................................................................................M8M.6 IC (Initial Condition).............................................................................................M8M.7 Signal Conversion ..................................................................................................M9M.8 Rate Transition.....................................................................................................M10M.9 Signal Specification ..............................................................................................M12M.10 Bus to Vector .......................................................................................................M13M.11 Data Type Propagation Examples .......................................................................M14M.12 Probe....................................................................................................................M15M.13 Weighted Sample Time.......................................................................................M17M.14 Width...................................................................................................................M18

    Signal Routing ................................................................................................................. N1

    N.1 Bus Creator ..............................................................................................................N1N.2 Bus Selector..............................................................................................................N1N.3 Bus Assignment .......................................................................................................N1N.4 Mux ..........................................................................................................................N4N.5 Demux......................................................................................................................N4N.6 Selector.....................................................................................................................N5N.7 Index Vector ............................................................................................................N8N.8 Merge .......................................................................................................................N9N.9 Environmental Controller.....................................................................................N10N.10 Manual Switch ......................................................................................................N12N.11 Multiport Switch...................................................................................................N13N.12 Switch....................................................................................................................N14N.13 From......................................................................................................................N14N.14 Goto Tag Visibility................................................................................................N15N.15 Goto ......................................................................................................................N16N.16 Data Store Read....................................................................................................N18N.17 Data Store Memory...............................................................................................N18Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCop

    N.18 Data Store Write ..................................................................................................N18

    O

    Pduction to Simulink with Engineering Applications, Third Edition ix

    N.19 Vector Concatenate..............................................................................................N20

    Sinks..................................................................................................................................O1

    O.1 Outport ................................................................................................................... O1O.2 Terminator.............................................................................................................. O1O.3 To File..................................................................................................................... O1O.4 To Workspace......................................................................................................... O3O.5 Scope....................................................................................................................... O4O.6 Floating Scope ........................................................................................................ O5O.7 XY Graph................................................................................................................ O9O.8 Display .................................................................................................................. O11O.9 Stop Simulation.................................................................................................... O12

    Sources ...............................................................................................................................P1

    P.1 Inport ........................................................................................................................P1P.2 Ground......................................................................................................................P1P.3 From File ...................................................................................................................P1P.4 From Workspace .......................................................................................................P1P.5 Constant....................................................................................................................P2P.6 Enumerated Constant...............................................................................................P2P.7 Signal Generator .......................................................................................................P7P.8 Pulse Generator.........................................................................................................P9P.9 Signal Builder ..........................................................................................................P10P.10 Ramp ......................................................................................................................P12P.11 Sine Wave...............................................................................................................P12P.12 Step.........................................................................................................................P14P.13 Repeating Sequence ...............................................................................................P14P.14 Chirp Signal ...........................................................................................................P15P.15 Random Number ...................................................................................................P16P.16 Uniform Random Number....................................................................................P17P.17 Band Limited White Noise....................................................................................P18P.18 Repeating Sequence Stair.......................................................................................P21P.19 Repeating Sequence Interpolated ..........................................................................P22P.20 Counter FreeRunning .........................................................................................P23P.21 Counter Limited ....................................................................................................P24P.22 Clock ......................................................................................................................P25P.23 Digital Clock ..........................................................................................................P26yright Orchard Publications

  • x

    Q

    R

    S

    TUserDefined Functions................................................................................................. Q1

    Q.1 Fcn........................................................................................................................... Q1Q.2 Interpreted MATLAB Function ............................................................................. Q2Q.3 MATLAB Function ................................................................................................ Q2Q.4 SFunction.............................................................................................................. Q6Q.5 Level2 MATLAB SFunction............................................................................... Q6Q.6 SFunction Builder ................................................................................................ Q9Q.7 SFunction Examples ........................................................................................... Q10

    Additional Discrete..........................................................................................................R1

    R.1 Transfer Fcn Direct Form II.....................................................................................R1R.2 Transfer Fcn Direct Form II Time Varying .............................................................R2R.3 Fixed-Point StateSpace ...........................................................................................R3R.4 Unit Delay External IC ............................................................................................R4R.5 Unit Delay Resettable...............................................................................................R5R.6 Unit Delay Resettable External IC...........................................................................R6R.7 Unit Delay Enabled..................................................................................................R7R.8 Unit Delay Enabled Resettable ................................................................................R8R.9 Unit Delay Enabled External IC..............................................................................R9R.10 Unit Delay Enabled Resettable External IC .........................................................R10R.11 Unit Delay With Preview Resettable ....................................................................R11R.12 Unit Delay With Preview Resettable External RV ...............................................R12R.13 Unit Delay With Preview Enabled........................................................................R13R.14 Unit Delay With Preview Enabled Resettable ......................................................R14R.15 Unit Delay With Preview Enabled Resettable External RV.................................R15

    Additional Math Increment / Decrement.................................................................. S1

    S.1 Increment Real World .............................................................................................. S1S.2 Decrement Real World............................................................................................. S1S.3 Increment Stored Integer.......................................................................................... S2S.4 Decrement Stored Integer......................................................................................... S3S.5 Decrement to Zero Block.......................................................................................... S3S.6 Decrement Time To Zero ......................................................................................... S4

    Simulink Extras................................................................................................................ T1

    T.1 Discrete Transfer Fcn with Initial States .................................................................. T1T.2 Discrete Transfer Fcn with Initial Outputs .............................................................. T2T.3 Discrete ZeroPole (with initial states) ..................................................................... T4T.4 Discrete ZeroPole (with initial outputs) ................................................................. T5T.5 Idealized ADC Quantizer ......................................................................................... T7Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCop

    T.6 Transfer Fcn (with initial states)............................................................................... T8

    U

    V

    W

    X

    Yduction to Simulink with Engineering Applications, Third Edition xi

    T.7 Transfer Fcn (with initial outputs) ........................................................................... T9T.8 ZeroPole (with initial states) ................................................................................. T10T.9 ZeroPole (with initial outputs) ............................................................................. T11T.10 StateSpace (with initial outputs) ......................................................................... T11T.11 Auto Correlator..................................................................................................... T12T.12 Cross Correlator.................................................................................................... T13T.13 Power Spectral Density.......................................................................................... T14T.14 Averaging Power Spectral Density......................................................................... T16T.15 Spectrum Analyzer................................................................................................. T17T.16 Averaging Spectrum Analyzer ............................................................................... T17T.17 Floating Bar Plot.................................................................................................... T18T.18 Clock...................................................................................................................... T20T.19 D Latch .................................................................................................................. T20T.20 D Flip Flop ............................................................................................................ T21T.21 SR Flip Flop......................................................................................................... T21T.22 JK Flip Flop ......................................................................................................... T22T.23 Switched Derivative for Linearization................................................................... T23T.24 Switched Transport Delay for Linearization ......................................................... T25T.25 Polar to Cartesian Transformation ....................................................................... T27T.26 Cartesian to Polar Transformation ....................................................................... T27T.27 Spherical to Cartesian Transformation................................................................. T28T.28 Cartesian to Spherical Transformation................................................................. T29T.29 Fahrenheit to Celsius Transformation.................................................................. T29T.30 Celsius to Fahrenheit Transformation.................................................................. T29T.31 Degrees to Radians Transformation ..................................................................... T30T.32 Radians to Degrees Transformation ..................................................................... T30

    Random Number Generation.........................................................................................U1

    U.1 Random Numbers...................................................................................................U1U.2 An Example.............................................................................................................U1

    Exercises............................................................................................................................ V1

    Solutions to the Exercises ...............................................................................................W1

    Weighted Moving Average .............................................................................................. X1

    Table of Simulink Blocks ................................................................................................ Y1yright Orchard Publications

  • xiiReferences.......................................................................................................................Ref1

    Index................................................................................................................................ IN1Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCopy

    Chapter 1

    stan

    1.1

    Thelyze,withchapple, showexam

    1.2

    Exam

    For

    and

    For

    and

    * Than

    Tduction to Simulink with Engineering Applications, Third Edition 11right Orchard PublicationsIntroduction to Simulink

    his chapter is an introduction to Simulink. This author feels that it is best to introduce Simu-link in this chapter with a few examples. Tools for simulation and modelbased designs arepresented in the subsequent chapters. Some familiarity with MATLAB is essential in under-

    ding Simulink, and for this purpose, Appendix A is included as an introduction to MATLAB.

    Simulink and its Relation to MATLAB

    MATLAB and Simulink environments are integrated into one entity, and thus we can ana- simulate, and revise our models in either environment at any point. We invoke Simulink fromin MATLAB. We begin with a few examples and we will discuss generalities in subsequentters. Throughout this text, a left justified horizontal bar will denote the beginning of an exam-and a right justified horizontal bar will denote the end of the example. These bars will not ben whenever an example begins at the top of a page or at the bottom of a page. Also, when oneple follows immediately after a previous example, the right justified bar will be omitted.

    Modeling an Electric Circuit

    ple 1.1

    the electric circuit of Figure 1.1, *is the input and the initial conditions are ,

    . We will compute .

    Figure 1.1. Circuit for Example 1.1this example,

    (1.1)

    by Kirchoffs voltage law (KVL),

    roughout this text, the designation will be used to denote the unit step function. We will use to denotey other input to be consistent with the MATLAB and Simulink designations.

    u0 t( ) iL 0( ) 0=

    u0 t( ) u t( )

    vc 0( ) 0.5 V= vC t( )

    +R L

    +

    C1

    vs t( ) u0 t( )=

    vC t( )i t( )

    1 4 H

    4 3 F

    i iL iC CdvCdt

    ---------= = =

  • Chapter 1 Introduction to Simulink

    11

    The initials conditions are specified at the MATLAB command prompt as

    x1=0

    As b

    clickdid

    1.3

    Themor

    Exam

    A fo

    wheand

    a. W

    b. It

    x1 x2[ ]'

    ; x2=0.5;

    efore, to start the simulation we click the icon, and to see the output waveform, we double

    the Scope block. Then we click on the Autoscale icon, and we scale the vertical axis as wewith the waveform of Figure 1.13. The waveform shown in Figure 1.16.

    Figure 1.16. The waveform for the function for Example 1.1 with the StateSpace block.

    Modeling a FourthOrder Differential Equation

    statespace block is the best choice when we need to display the output waveform of three ore variables as illustrated by the following example.

    ple 1.2

    urthorder network is described by the differential equation

    (1.27)

    re is the output representing the voltage or current of the network, and is any input,the initial conditions are .

    e will express (1.27) as a set of state equations

    is known that the solution of the differential equation

    (1.28)

    vC t( )

    d 4ydt4--------- a3

    d 3ydt3--------- a2

    d2ydt2-------- a1

    dydt------ a0 y t( )+ + + + u t( )=

    y t( ) u t( )y 0( ) y' 0( ) y'' 0( ) y''' 0( ) 0= = = =

    d4ydt4-------- 2d

    2ydt2-------- y t( )+ + tsin=4 Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCopy

    Modeling a Fourth-Order Differential Equation

    s

    I

    t

    1. Ta

    Wd

    W

    a

    I

    A

    w

    an

    re

    aubject to the initial conditions , has the solution

    (1.29)

    n our set of state equations, we will select appropriate values for the coefficients so that the new set of the state equations will represent the differential equa-

    ion of (1.28) and using Simulink, we will display the waveform of the output .

    he differential equation of (1.28) is of fourthorder; therefore, we must define four state vari-bles that will be used with the four firstorder state equations.

    e denote the state variables as , and , and we relate them to the terms of the givenifferential equation as

    (1.30)

    e observe that

    (1.31)

    nd in matrix form

    (1.32)

    n compact form, (1.32) is written as(1.33)

    lso, the output is(1.34)

    here

    (1.35)

    d since the output is defined as

    lation (1.34) is expressed as

    y 0( ) y' 0( ) y'' 0( ) y''' 0( ) 0= = = =

    y t( ) 0.125 3 t2( ) 3t tcos[ ]=

    3 a2 a1 and a0, , ,y t( )

    x1 x2 x3, , x4

    x1 y t( )= x2 dydt------= x3d 2ydt2---------= x4

    d 3ydt3---------=

    x1 x2=x2 x3=x3 x4=

    d 4ydt4--------- x4 a0x1 a1x2 a2x3 a3x4 u t( )+= =

    x1x2x3x4

    0 1 0 00 0 1 00 0 0 1a0 a1 a2 a3

    x1x2x3x4

    0001

    u t( )+=

    x Ax bu+=

    y Cx du+=

    x

    x1x2x3x4

    = A

    0 1 0 00 0 1 00 0 0 1a0 a1 a2 a3

    = x

    x1x2x3x4

    = b

    0001

    and u,=, , , u t( )=

    y t( ) x1=duction to Simulink with Engineering Applications, Third Edition 115right Orchard Publications

  • Chapter 1 Introduction to Simulink

    11

    2. B(1

    an

    w

    S

    in

    WLawSth(1.36)

    y inspection the differential equation of (1.27) will be reduced to the differential equation of.28) if we let

    d thus the differential equation of (1.28) can be expressed in statespace form as

    (1.37)

    here

    (1.38)

    ince the output is defined as

    matrix form it is expressed as

    (1.39)

    e invoke MATLAB, we start Simulink by clicking on the Simulink icon, on the Simulinkibrary Browser, we click the Create a new model (blank page icon on the left of the top bar),nd we save this model as Example_1_2. On the Simulink Library Browser we select Sources,e drag the Signal Generator block on the Example_1_2 model window, we click and drag thetateSpace block from the Continuous on Simulink Library Browser, and we click and drage Scope block from the Commonly Used Blocks on the Simulink Library Browser. We also

    y 1 0 0 0[ ]

    x1x2x3x4

    0[ ]u t( )+=

    a3 0= a2 2= a1 0= a0 1= u t( ) tsin=

    x1x2x3x4

    0 1 0 00 0 1 00 0 0 1a0 0 2 0

    x1x2x3x4

    0001

    tsin+=

    x

    x1x2x3x4

    = A

    0 1 0 00 0 1 00 0 0 1a0 0 2 0

    = x

    x1x2x3x4

    = b

    0001

    and u,=, , , tsin=

    y t( ) x1=

    y 1 0 0 0[ ]

    x1x2x3x4

    0[ ] tsin+=6 Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCopy

    Modeling a Fourth-Order Differential Equation

    afo

    WB

    W

    T

    A

    F

    U

    NF

    A

    B

    C

    D

    In

    A

    Nlo

    a

    Wicdd the Display block found under Sinks on the Simulink Library Browser. We connect theseur blocks and the complete block diagram is as shown in Figure 1.17.

    Figure 1.17. Model for Example 1.2 with the parameters specified below

    e now doubleclick the Signal Generator block and we enter the following in the Functionlock Parameters dialog box the following:

    ave form: sine

    ime (t): Use simulation time

    mplitude: 1

    requency: 2

    nits: Hertz

    ext, we doubleclick the StateSpace block and we enter the following parameter values in theunction Block Parameters:

    : [0 1 0 0; 0 0 1 0; 0 0 0 1; a0 a1 a2 a3]

    : [0 0 0 1]

    : [1 0 0 0]

    : [0]

    itial conditions: x0

    bsolute tolerance: auto

    ow, we switch to the MATLAB command window and at the command prompt we type the fol-wing values:

    0=1; a1=0; a2=2; a3=0; x0=[0 0 0 0];

    e change the Simulation Stop time to , and we start the simulation by clicking on the on. To see the output waveform, we doubleclick the Scope block, then we click the Autoscale

    icon, and we obtain the waveform shown in Figure 1.18.

    25duction to Simulink with Engineering Applications, Third Edition 117right Orchard Publications

  • Chapter 1 Introduction to Simulink

    11

    The

    Examcoul

    1.4

    Exam

    We unkbloc

    The

    TheFigure 1.18. Waveform for Example 1.2

    Display block in Figure 1.17 shows the value at the end of the simulation time.

    ples 1.1 and 1.2 have clearly illustrated that the StateSpace is indeed a powerful block. Wed have also obtained the solution of Example 1.2 using four Integrator blocks.

    Modeling the Solution of Three Equations with Three Unknowns

    ple 1.3

    will create a model that will produce the simultaneous solution of three equations with threenowns using Algebraic Constraint blocks found in the Math Operations library, Displayks found in the Sinks library, and Gain blocks found in the Commonly Used Blocks library.

    model will display the values for the unknowns , , and for the system of the equations

    (1.40)

    model is shown in Figure 1.19.

    z1 z2 z3

    a1z1 a2z2 a3z3 k1+ + + 0=

    a4z1 a5z2 a6z3 k2+ + + 0=

    a7z1 a8z2 a9z3 k3+ + + 0=8 Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCopy

    Modeling the Solution of Three Equations with Three Unknowns

    Nex

    a1=

    Afte

    and

    An Athis backfor tzeroFigure 1.19. Model for Example 1.3 with the entries specified below

    t, at the MATLAB command prompt we enter the following values:

    2; a2=3; a3=1; a4=1; a5=5; a6=4; a7=6; a8=1; a9=2; k1=8; k2=7; k3=5;

    r clicking on the simulation icon, we obtain the values of the unknowns as , ,

    as shown in the Display blocks in Figure 1.19.

    lgebraic Constraint block constrains the input signal to zero, outputs a value for , andvalue eventually produces a zero at the input. Thus, output is fed back to the input via a feed- path. We can improve the efficiency of the algebraic loop solver by providing an initial guesshe algebraic state that is close to the final solution value. By default, the initial guess value is.

    z1 2= z2 3=

    z3 5=

    f z( ) z

    zduction to Simulink with Engineering Applications, Third Edition 119right Orchard Publications

  • Chapter 1 Introduction to Simulink

    12

    1.5 Representing a Model as a Subsystem

    An oand

    Exam

    For from

    1.20

    a1=

    The

    at th

    1.6

    At taddihighlinklinkinvo

    * TSwutstanding feature in Simulink is the representation of a large model consisting of many blockslines, to be shown as a single Subsystem block.

    ple 1.4

    instance, to group all blocks and lines in the model of Figure 1.19 except the display blocks, the Edit drop menu we choose Create Subsystem and this model will be shown as in Figure

    * where at the MATLAB command prompt we have entered the following values:

    5; a2=1; a3=4; a4=11; a5=6; a6=9; a7=8; a8=4; a9=15; k1=14; k2=6; k3=9;

    Figure 1.20. The model in Figure 1.19 represented as a subsystem

    Display blocks in Figure 1.20 show the values of , , and for the values that we specified

    e MATLAB command prompt above.

    Simulink Demos

    his time, the reader with no prior knowledge of Simulink, should be ready to learn Simulinkstional capabilities. We will explore other features in the subsequent chapters. However, it isly recommended that the reader becomes familiar with the block libraries found in the Simu- Library Browser. Then, the reader can follow the steps delineated in The MathWorks Simu- Users Manual to run the Demo Models beginning with the thermo model. This model canked by typing thermo at the MATLAB command prompt.

    he contents of the Subsystem block are not lost. We can doubleclick on the Subsystem block to see its contents. Theubsystem block replaces the inputs and outputs of the model with Inport and Outport blocks. These blocks alongith the Subsystem block are described in Section 2.1, Chapter 2, Page 22.

    z1 z2 z30 Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • Chapter 2 Mathematical Applications

    26 Introduction to Simulink with Engineering Applications, Third Edition Copyright Orchard Publications

    Figure 2.4. Simulink model for the constraints

    Figure 2.5. Plot of the constraints as displayed in Scope block in Figure 2.4

    Sum 2

    Sum 1Scope

    Product

    Mux

    1/3

    Constant 3

    24

    Constant 2

    20

    Constant 1

    Clock

    aa

  • Chapter 2 Mathematical Applications

    218 Introduction to Simulink with Engineering Applications, Third Edition Copyright Orchard Publications

    With the model in Figure 2.18 open, we enter the following values at the MATLAB commandprompt:

    PP=90000; SV=45000; n=15; AE=40950; i=0.045;

    and the Display block in Figure 2.19 displays the value of the cost if Route A is chosen.

    Figure 2.19. Model for Comparison of Alternate Proposals - Route A

    Next we enter the following values at the MATLAB command prompt:

    PP=155000; SV=30000; n=15; AE=9400; i=0.045;

    Figure 2.20. Model for Comparison of Alternate Proposals - Route B

  • Ball Thrown Vertically UpwardFigure 3.4. Model for the ball thrown vertically upwardIntroduction to Simulink with Engineering Applications, Third Edition 37Copyright Orchard Publications

  • Chapter 4 Thermodynamics and Fluid Mechanics ApplicationsFigure 4.2. Model for the rise of water in a capillary tube at temperature in

    For the model in Figure 4.2, we have entered the values

    temp_table=[ 0 5 10 15 20 30 40 50 60 70 80 90 100];

    T o C42 Introduction to Simulink with Engineering Applications, Third Edition Copyright Orchard Publications

  • Chapter 5 Assortment of Math and Engineering Applications

    56

    To tScopFigu

    Theobtabelo

    Sinc

    andsym

    yield

    5.4

    A heFiguFigure 5.6. The MATLAB Function block with the userdefined function

    he MATLAB Function block model we add the Clock block from the Sources library, and thee block from the Sinks library. We connect the three blocks and the model is now as shown inre 5.7, and we execute the simulation command.

    Figure 5.7. Model for the beam deflection example

    waveform indicates the maximum deflection occurs when . The exact result isined by taking the first derivative of the given function and setting it equal to zero as shownw.

    e is not a viable solution, with , we obtain

    s x y; y=solve('x^2187.5*x+7500')

    s , and

    Tractrix Curve

    avy object is dragged along a rough horizontal plane by a string of length as shown inre 5.8.

    x 0.58L

    dy dx 8x3 15 Lx2 6L2x+ x 8x2 15Lx 6L2+( ) 0= = =x 0= L 100=

    8x2 1500x 60000+ 0=

    x2 187.5x 7500+ 0=

    x 57.85= y 2.5997=

    P PQ a Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCop

    Discrete Time Integration with Variable Amplitude Input

    The final step is to add with . This addition is performed with the model in Figure 5.53whe

    Theimp

    5.21

    It isEuleFigu

    V 'C2 V ''C2duction to Simulink with Engineering Applications, Third Edition 537

    re the models of Figures 5.51 and 5.52 have been converted to Subsystems 1 and 2 respectively.

    Figure 5.53. Model for the addition of with

    model in Figure 5.53 can now be used with the circuit of Figure 5..48 for any values of theedances .

    Discrete Time Integration with Variable Amplitude Input

    showm in Appendix V, Exercise 16, that when the input signal is a pulse, a Discrete Forwardr Integrator and a Discrete Trapezoidal Integrator will produce the same result. The model inre 5.54 uses an input that varies in amplitude during a sample period.

    Figure 5.54. Model for Discrete Time Integration with variable amplitude input

    V'C2 V''C2

    Zyright Orchard Publications

  • IntroCop

    SFunction Example 2

    The syntax for the diode_sfcn.m file above is the similar to that in Example L.20, Page L62,App

    Nextionnam

    Fi

    5.23

    Equ

    or

    Let

    For are:duction to Simulink with Engineering Applications, Third Edition 541

    endix L

    t, we open a new model window, from the UserDefined Functions Library we drag an SFunc- block into it, we doubleclick this block, in the Function Block Parameters dialog box wee it diode_sfcn, and we add and interconnect the other blocks shown in Figure 5.74.

    gure 5.56. Model and waveforms for temperature coefficients in semiconducto diodes using an SFunction block

    SFunction Example 2

    ation (5.50) below is same as equation (5.20) in Section 5.7, Page 512

    (5.50)

    (5.51)

    , and . Then , and .

    this example we let , , , and . Then, our statespace equations

    Scope 1 Scope 2

    M Jd2

    dt2-------- cd

    dt------ mgL sin+ +=

    d2dt2-------- 1

    J--- M cddt

    ------ mgL sin =

    x1= d dt x2= x1 x2= x2

    d2 dt2 1 J( ) M cx2 mgLx1( )= =

    J 2= M 1= c 0.2= mgL 2=yright Orchard Publications

  • Appendix A Introduction to MATLAB

    A2

    % Tmagrndzthetapolaylab

    Exam

    600Figure A.12. Plot for the imaginary part of the impedance in Example A.15

    he last six statements (next five lines) below produce the polar plot of z=abs(z);% Computes |Z|;...=round(abs(z));% Rounds |Z| to read polar plot easier;...=angle(z);% Computes the phase angle of impedance Z;...

    r(theta,rndz);% Angle is the first argumentel('Polar Plot of Z'); grid

    Figure A.13. Polar plot of the impedance in Example A.15

    ple A.15 clearly illustrates how powerful, fast, accurate, and flexible MATLAB is.

    0 200 400 600 800 1000 1200 1400 1600 1800 2000-600

    -400

    -200

    0

    200

    400

    radian frequency w

    Imag

    inar

    y pa

    rt of

    Z

    500

    1000

    1500

    30

    210

    60

    240

    90

    270

    120

    300

    150

    330

    180 0

    Pol

    ar P

    lot o

    f Z4 Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • Appendix B Masked Subsystems

    B8

    Wit

    and

    show

    ThethattypeFigure B.9. The Function Block Parameters window with the values of the constants

    h the variables defined as above, the masked subsystem implements the quadratic equation

    the roots of this equation are and . Our model is tested for the first root as

    n in Figure B.10.

    Figure B.10.

    Mask Editor also contains the Initialization tab that allows us to enter MATLAB commands initialize the masked subsystem, and the Documentation tab that lets us define or modify the description and help text for a masked subsystem. These tabs are not used in this example.

    y x2 5x 6+=

    x1 2= x2 3= Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • Appendix C Commonly Used

    C22 Introduction to Simulink with Engineering Applications, Third Edition Copyright Orchard Publications

    Example C.10

    For the model in Figure C.26, at the MATLAB command prompt we have entered the statementT=75; the Function Block Parameters dialog box for the Switch block has been set for u2>Thresh-old, Threshold =T, in the Source Block Parameters dialog box for the functionblock we have entered Amplitude=1, Bias=75, Frequency =1, , and for the

    function block we have entered Amplitude=1, Bias=75, Frequency =1,. Unlisted parameters are left in their default states. With the simulation time set at

    , the waveforms indicated on the Scope block in Figure C.27 show that at the end of the sim-ulation time the function has attained the value of and the function has attained the value of . Since the Threshold value is set at and the criterion isu2>Threshold, the Switch block outputs the value of , that is, the value of the Display 3 blockat the end of the simulation time.

    Figure C.26. Switch block set for u2>Threshold, Threshold T=75

    Figure C.27. Input waveforms for the model in Figure C.26

    y 75 xsin+=Phase 0=

    z 75 xsin=Phase =10 sec

    z 75 xsin= 75.54 y 75 xsin+=74.46 75

    75.54

  • IntroCop

    Vector Concatenate

    Thebloc

    Not

    C.1

    TheAppnatisignnati

    The

    Exam

    We duction to Simulink with Engineering Applications, Third Edition C49

    Figure C.59. Model for Example C.21

    Data Type Demonstration Simulink demo is another model using Data Type Conversionks. It can be accessed by typing datatypedemo at the MATLAB command prompt.

    e: The MATLAB and Simulink builtin integer data types are limited to 32 bits. If we want tooutput fixedpoint numbers in the range 33 and 53 bits, we can break the number intopieces using Gain blocks. For details please refer to the Simulink Help menu for an example.

    8 Vector Concatenate

    Vector Concatenate block is a special case of the Matrix Concatenate block described inendix I, where the block operates in Vector Concatenation Mode, Horizontal Matrix Concate-on Mode, or Vertical Matrix Concatenation Mode. In Vector Concatenation Mode, all inputals must be either row vectors ( matrices) or column vectors ( matrices) or a combi-on of vectors and either row or column vectors. The output is a vector if all inputs are vectors.

    output is a row or column vector if any of the inputs are row or column vectors, respectively.

    ple C.22

    will create a model using a Vector Concatenate block to concatenate vertically the column vec-

    1 m m 1yright Orchard Publications

  • Introduction to Simulink with Engineering Applications, Third Edition D13Copyright Orchard Publications

    PID Controller

    absence of an integral value prevents the system from reaching its target value due to the controlaction.

    In general, we add a proportional control to improve the rise time, we add a derivative control toimprove the overshoot, and we add an integral control to eliminate the steady-state error. Then, weadjust each of Kp, Ki, and Kd until we obtain a desired overall response.

    Example D.4

    The model in Figure D.18 produces the outputs of a transfer function without and with PID con-trol. The output waveforms are shown in Figure D19.

    Figure D.18. Model for Example D.4

    Figure D.19. Output waveforms for the model in Figure D.18 without and with PID control

    The Simulink documentation contains the Anti-Windup Control Using a PID Controller, and BumplessControl Transfer Between Manual and PID Control demos.They can be accessed by typingsldemo_antiwindup and sldemo_bumpless at the MATLAB command prompt.

  • Introduction to Simulink with Engineering Applications, Third Edition D15Copyright Orchard Publications

    PID Controller (2DOF)

    Figure D.20. Armature circuit and inertial load for a DC motor

    Figure D.21 is the block diagram of the DC motor where , i.e., the torque that

    the motor has to overcome for motion to occur, and Figure D.22 is a model for this block diagramwhere the integrator block on the right side has been omitted for simplicity.

    Figure D.21. Block diagram of a DC motor

    Figure D.22. Model for the block diagram in Figure D.21

    Va s( )

    Las Ra

    Vb s( ) Kbm s( )=

    Tm s( ) KiIa s( )=m s( )

    Bm

    Jms

    Armature circuitInertial load

    Ia s( )

    shaft angle( )m s( )

    TL s( ) load torque=

    1Las Ra+----------------------

    +

    Va s( ) Ia s( ) 1Jms Bm+----------------------Tm s( ) m s( )

    Vb s( )

    TL s( )

    Kb

    Ki

    1s---

    m s( )

  • Appendix D ContinuousTime

    D30 Introduction to Simulink with Engineering Applications, Third Edition Copyright Orchard Publications

    Figure D.45. Model to illustrate the use of the Variable Time Delay block

    Figure D.46. Input and output waveforms for the model in Figure D.45

    Example D.12

    The model in this example compares the distance traveled by two automobiles that departed frompoint A, one three hours after the other at different speeds, and stopped at point B ten hours later.

  • IntroCopy

    Appendix E

    eachpleticon

    E.1

    Therangunchlowebloc

    Exam

    Thethe

    * A

    T

    0.25duction to Simulink with Engineering Applications, Third Edition E1right Orchard PublicationsDiscontinuities

    his appendix is an introduction to the Discontinuities Blocks library. This is the thirdlibrary in the Simulink group of libraries and contains the blocks shown below. Their func-tions are illustrated with examples. In this appendix we will briefly describe the function of

    block included in this group, and their application will be illustrated with examples. The com-e description of each block can be found in the Simulink documentation. For emphasis, the of each Simulink block described in its section is shown in drop shadows.

    Saturation

    Saturation block sets upper and lower bounds on a signal. When the input signal is within thee specified by the Lower limit and Upper limit parameters, the input signal passes throughanged. When the input signal is outside these bounds, the signal is clipped to the upper orr bound. When the Lower limit and Upper limit parameters are set to the same value, thek outputs that value. This block is also described in Section 2.13, Chapter 2, Page 221.

    ple E.1 *

    model shown in Figure E.1 uses a Saturation block whose upper limit is clipped at andlower limit is clipped at . The input is a sine function with amplitude and frequency

    . The input and output waveforms are shown in Figure E.2.

    Figure E.1. Model for Example E.1

    nother example with the Saturation block is presented as Example 2.13, Chapter 2, Page 221.

    +0.250.25 1

    Hz

  • Appendix E Discontinuities

    E1

    E.11 Coulomb and Viscous Friction

    As wmotas bbrakity, aevenforce

    TheVisc

    The

    whe

    The

    and

    TheTheCouthestatiofrictdefa

    Fe know from physics, friction is a force that resists the relative motion or tendency to suchion of two bodies in contact. Friction is undesirable in some parts of rotating machinery suchearings and cylinders, but very beneficial in the automotive industry such as the design ofes and tires. Theoretically, there should be no friction in a motor with zero velocity, but in real- small amount of static (no velocity) friction known as Coulomb friction, is always present in roller or ball type antifriction bearings. Viscous friction, on the other hand, is friction caused by the viscosity of lubricants.

    Coulomb friction function, the Viscous friction function, and the combined Coulomb plusous friction functions are illustrated in Figure E.21.

    Figure E.31. Coulomb friction and Viscous friction functions

    Coulomb friction function is defined as

    (E.4)

    re is the Coulomb friction coefficient.

    Viscous friction function is defined as

    (E.5)

    the Coulomb plus Viscous friction is defined as

    (E.6)

    Coulomb and Viscous Friction block produces an offset at zero and a linear gain elsewhere. offset corresponds to the Coulombic friction; the gain corresponds to the viscous friction. lomb friction force can be represented by at least four different continuous functions. Each ofe functions involves one constant that controls the level of accuracy of that function's represen-n of the friction force. Simulink uses the default values for the offset (Coulombion value). For the signal gain (coefficient of viscous friction) at nonzero input points theult is 1. For a detailed description, please refer to the Simulink documentation.

    (a) Coulomb friction (b) Viscous friction (c) Coulomb plus Viscous friction

    riction force Friction force Friction force

    Sliding velocity Sliding velocity Sliding velocity

    CFn VvFn

    FfcvFfvFfc

    v v v

    Ffc CFn=

    C

    Ffv vvFn=

    Ffc fv+ vvFn C Fn=

    1 3 2 0[ ]8 Introduction to Simulink with Engineering Applications, Third EditionCopyright Orchard Publications

  • IntroCop

    Transfer Fcn Lead or Lag

    ans =

    (5*or

    The

    F.12

    Leadincrnatetorsdesi

    Thegainand

    In g

    0 z

  • IntroCop

    Discrete FIR Filter

    That is, the number of moving average sequence is equal to values. Thus, with of aten-v

    Exam

    The

    whethis

    Thefor tFIR

    n k 1+ k 4=

    n kduction to Simulink with Engineering Applications, Third Edition F23

    alue ( ) sequence, the moving average sequence has values.

    ple F.14

    price of a particular security (stock) over a 10day trading period is as follows:

    re the last value is the most recent. We will create a model of moving averages with over 10day t rading per iod. For this example , the moving average sequence has

    values.

    model is shown in Figure F.30, and the settings for the Function Block Parameters dialog boxhe Discrete FIR Filter 1 block is shown in Figure F.31. The settings for the remaining Discrete Filter blocks are shown in the model.

    Figure F.30. Model for Example F.14

    n 10= n k 1+ 10 4 1+ 7= =

    77 80 82 85 90 84 81 82 86 79

    k 5=

    1+ 10 5 1+ 6= =yright Orchard Publications

  • Appendix G Logic and Bit Operations

    G2 Introduction to Simulink with Engineering Applications, Third Edition Copyright Orchard Publications

    Example G.2

    Let represent an array of numbers or a time-varying signal. The model in Figure G.2 proves that

    in general, . The term on the left implies that must first be squared and the

    average value is then to be found. The term on the right implies that the average value of must befound first, and then the average must be squared. For this model each of the elements of the array[1 2 3 4 5] is first squared and the mean (average) value is found to be . Then, the mean is firstfound and its square is computed and found to be . Since the results are different, the RelationalOperator block outputs logical .

    Figure G.2. Model for Example G.2

    G.3 Interval Test

    The Interval Test block performs a test to determine if a signal is in a specified interval. The blockoutputs TRUE if the input is between the values specified by the Lower limit and Upper limitparameters. The block outputs FALSE if the input is outside those values. The output of the blockwhen the input is equal to the Lower limit or the Upper limit is determined by whether the boxesnext to Interval closed on left and Interval closed on right are selected in the dialog box.

    Example G.3

    For the model shown in Figure G.3 the Upper limit parameter for the Interval Test block is set tothe binary value , the Lower limit is set to the binary value , and the boxesnext to Interval closed on left and Interval closed on right are selected in the dialog box. The largestpositive value and the smallest negative value have been selected and the Interval Test block out-puts TRUE (1).

    x

    ave x2( ) xave( )2 x

    x

    119

    0

    01111111[ ] 10000000[ ]

  • Introduction to Simulink with Engineering Applications, Third Edition H1Copyright Orchard Publications

    Appendix H

    Lookup Tables

    his appendix is an introduction to the Lookup Tables Group of blocks and only a briefdescription is given. A complete description of each block can be found in the The Math-Works Simulink documentation. Their functions are illustrated with examples. The termi-

    nology monotonically increasing * is used throughout this chapter, and it is defined in the footnotebelow.

    H.1 Lookup Table

    The Lookup Table block computes an approximation to a function where the data vec-tors x and y are given, and it is required that the x data vector must be monotonically increasing.Moreover, the length of the x and y data vectors must be the same.

    The Simulink documentation states that in a future release, the Lookup Table block will beremoved from the Lookup Tables library and replaced with a 1D version of the Lookup Table(nD) block. Existing models that contain the Lookup Table block continue to work for backwardcompatibility.

    Example H.1

    The model in Figure H.1 uses a Lookup Table block to find the radioactive material left after

    if a isotope initially containing gm of that material. It is known that

    the halflife of the Uranium isotope 234 is approximately and has a

    disintegration constant . The number of radioactive atoms of the originalkind still present at any time is computed from the relation

    (H.1)

    * Monotonically increasing and monotonically decreasing sequences are sequences in which the successive values either consistentlyincrease or decrease but do not oscillate in relative value. Each value of a monotonic increasing sequence is greater than, or equalto the preceding value; likewise, each value of a monotonic decreasing sequence is less than, or equal to the preceding value.Stated in other words, a monotonically increasing function is one resulting from a partially ordered domain to a partially orderedrange such that implies that . Likewise, a monotonically decreasing function is one resulting from a partiallyordered domain to a partially ordered range such that implies that .

    Isotopes are atoms which have the same atomic number (number of protons) but different number of neutrons. The sum of thenumber of protons and neutrons in the nucleus is referred to as the mass number. The superscript 234 represents the mass num-ber.

    T

    x y f x( ) f y( )x y f x( ) f y( )

    y f x( )=

    1.5 105 yr U234 3 10 3

    T1 2( ) U234( ) 2.48 105 yr 8.8 10 14 sec 1=

    t

    N N0et N0e

    t = =

  • Introduction to Simulink with Engineering Applications, Third Edition H3Copyright Orchard Publications

    Lookup Table

    Figure H.1. Model for Example H.1

    Another example using this block appears in the Simulink Modeling AntiLock Braking Systemdemo. It can be accessed by typing sldemo_absbrake at the MATLAB command prompt.

  • Introduction to Simulink with Engineering Applications, Third Edition I3Copyright Orchard Publications

    Sum of Elements

    I.4 Sum of Elements

    The Sum of Elements block is another form of the Add block described above with one input andone output.

    Example I.4

    The model in Figure I.4 illustrates Gibbs phenomenon.*

    Figure I.4. Model for Example I.4

    I.5 Bias

    The Bias block adds a bias (offset) to the input signal.

    * The Gibbs phenomenon shows that Fourier series sums overshoot at a jump discontinuity, and that this overshoot doesnot disappear as the number of harmonics increases. For a detailed discussion please refer to Chapter 7, Signals andSystems, ISBN 978-1-934404-11-9.

  • Introduction to Simulink with Engineering Applications, Third Edition I13Copyright Orchard Publications

    Polynomial

    Figure I.17. Model for Example I.17

    I.18 Polynomial

    The Polynomial block accepts the real coefficients a polynomial in the Parameters dialog box andat the input we specify real values at which the polynomial will be evaluated. It is equivalent to theMATLAB polyval function.

    Example I.18

    We will create a model using the Polynomial block to evaluate the polynomial

    at , , and .

    The model is shown in Figure I.18 where at the MATLAB command prompt we have entered thecoefficients of , i.e.,

    px=[1 3 0 5 4 3 2];

    and in the Parameters dialog box for the Polynomial block we have typed px.

    p x( ) x6 3x5 5x3 4x2 3x 2+ + +=x 3.7= x 4.0= x 8.1=

    p x( )

  • IntroCop

    Check Dynamic Upper Bound

    value of . This model is configured to display error messages when the amplitude exceeds

    Thequenblocgrapto d

    J.6

    Thenal iinpuis ha

    Exam

    For valu

    1 volt1 v

    +1 vduction to Simulink with Engineering Applications, Third Edition J5

    .

    Signal Generator block has been specified as a sine waveform with the amplitude set at 1.1, fre-cy at 0.1 Hz, Constant block with the value shown, in the Check Dynamic Lower Bound

    k the Enable assertion and Output assertion signal are checked, and the icon type is selected ashic. The Convert block was inserted to convert the Boolean output of the Lower Bound block

    ouble as required by the Mux block.

    Figure J.5. Model for Example J.5

    Check Dynamic Upper Bound

    Check Dynamic Upper Bound block performs checks to verify that the amplitude of a test sig-s greater than the amplitude of a reference signal. The test signal is the signal connected to thet labeled sig. If the verification condition is true, the block takes no action. If not, simulationlted and an error message is displayed.

    ple J.6

    the model in Figure J.6 the amplitude of a sinusoidal signal may vary from its nominale of . The model is configured to display error messages when the amplitude exceeds

    .

    olt

    10%1 volt

    oltyright Orchard Publications

  • Introduction to Simulink with Engineering Applications, Third Edition K1Copyright Orchard Publications

    Appendix K

    ModelWide Utilities

    his appendix presents a brief description of the Simulink ModelWide Utilities group. Thefunction of each block and their inputoutput signals are illustrated with examples. Formore information please refer to the Simulink documentation for each block.

    K.1 TriggerBased Linearization

    The TriggerBased Linearization block, when triggered (by an external signal, e.g., a Pulse Genera-tor), invokes the MATLAB functions linmod or dlinmod to create a linear model for the system atthe current operating point. No trimming* is performed. The linear model is stored in the baseworkspace with the name of the model appended by _Trigger_Based_Linearization, for instance,Example01_Trigger_Based_Linearization. The structure has the fields shown in the Help menufor this block.

    Example K.1

    We will use a TriggerBased Linearization block to extract the linear model for the model shownin Figure K.1.

    Figure K.1. Model for Example K.1

    This is the same model as that in Figure D.4, Example D.3, Page D4, Appendix D, where with theexecution of the command [A,B,C,D]=linmod('Fig_D_04') the linear model in the form of thestatespace MATLAB displayed the four matrices as

    * The trim function uses a Simulink model to determine steadystate points of a dynamic system that satisfy input, out-put, and state conditions that we can specify. For details please type help trim at the MATLAB command prompt.

    T

  • IntroCop

    Enable (added to subsystem block)

    Fduction to Simulink with Engineering Applications, Third Edition L15

    igure L.18. Outputs when the Pulse Generator block is removed from the subsystem of Figure L.17

    Figure L.19. The Enable block with the Show output selectedyright Orchard Publications

  • Appendix L Ports & Subsystems

    L2

    The library is saved, and a Configurable Subsystem block in the library which now appears assh


Recommended