bab03- the cont blocks lib

Upload: cakmad69

Post on 01-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 BAB03- The Cont Blocks Lib

    1/20

    Introduction to Simulink with Engineering Applications 3−1Copyright© Orchard Publications

    Chapter 3

    The Continuous Blocks Library

    his chapter is an introduction to the Continuous Blocks library. This is the second libraryin the Simulink group of libraries and contains the Continuous −Time Linear SystemsSub −Library , and the Continuous −Time Delays Sub −Library blocks shown below. We

    will describe the function of each block included in this library and we will perform simulationexamples to illustrate their application.

  • 8/9/2019 BAB03- The Cont Blocks Lib

    2/20

    Chapter 3 The Continuous Blocks Library

    3− 2 Introduction to Simulink with Engineering Applications Copyright© Orchard Publications

    3.1 The Continuous − Time Linear Systems Sub − Library

    The Continuous − Time Linear Systems Sub − Library contains the blocks described in Subsec-tions 3.1.1 through 3.1.5 below.

    3.1.1 The Integrator Block

    The Integrator block is described in Section 2.14, Chapter 2, Page 2 − 20.

    3.1.2 The Derivative Block

    The Derivative block approximates the derivative of its input. The initial output for the block iszero. The accuracy of the results depends on the size of the time steps taken in the simulation.Smaller steps allow a smoother and more accurate output curve from this block. Unlike blocksthat have continuous states, the solver does not take smaller steps when the input changes rap-idly. Let us consider the following simple example.

    Example 3.1

    We will create a model that will compute and display the waveform of the derivative of the func-tion .

    The model is shown in Figure 3.1, and the input and output waveforms are shown in Figure 3.2.

    Figure 3.1. Model for Example 3.1

    To convert the sine function in the Sine Wave block to a cosine function, in the Source BlockParameters dialog box we specify . As we know, the derivative of the cosine func-tion is the negative of the sine function and this is shown in Figure 3.2.

    y xcos=

    Phase π 2 ⁄ =

  • 8/9/2019 BAB03- The Cont Blocks Lib

    3/20

    Introduction to Simulink with Engineering Applications 3−3Copyright© Orchard Publications

    The Continuous −Time Linear Systems Sub −Library

    To scale the vertical axis in Figure 3.2, we move the cursor near that axis, we right −click, and weset the values as indicated. We will follow this practice in subsequent illustrations.

    Figure 3.2. Input and output waveforms for the model of Figure 3.1

    The Simulink Help for the derivative block states that using the MATLAB function linmod tolinearize a model that contains a Derivative block can be troublesome. Let us elaborate on linear-ization.

    We prefer to work with linear functions since the slope is constant and thus we can find the out-put for any input. Unfortunately, the equations that describe the behavior of most physical phe-nomena are non −linear. If we are interested in values of the function close to some point (a,b), wecan replace the given function by its first Taylor polynomial, which is a linear function. * We recallthat the Taylor series are defined as in relation (3.1) below.

    (3.1)

    In (3.1), the first two terms on the right side define an equation of a straight line, i.e., ,

    a linear function. For example, if , the first two terms on the right side of (3.1) atpoint x=3 are represented by . The same is true for a function of two vari-ables, say and , i.e., , where if we let denote the local linearization at the point ,we get

    (3.2)

    * The first Taylor polynomial is often called the local linearization.

    f x( ) f x0( ) f ′ x0( ) x x0–( )f ′′ x0( )

    2!---------------- x x0–( )

    2 …f n( ) x0( )

    n!------------------- x x0–( )

    n+ + + +=

    y mx b+=

    y f x( ) x2= =

    9 6 x 3–( )+ 6x 9–=

    x y x y ,( ) L a b ,( )

    L x y,( ) f a b,( )= f ∂x∂

    ----- a b,( ) x a–( ) f ∂y∂

    ----- a b,( ) y b–( )+ +

  • 8/9/2019 BAB03- The Cont Blocks Lib

    4/20

    Chapter 3 The Continuous Blocks Library

    3−4 Introduction to Simulink with Engineering Applications Copyright© Orchard Publications

    Relation (3.2) yields the three numbers required to define the local linearization. The first numberis the value of at point , the second is the value of the partial derivative with respect toat point , and the third is the value of the partial derivative with respect to at point .

    Taking the partial derivative of and evaluating it at the point we find

    that the local linearization is . We observe that this locallinearization contains and terms of first degree. We can plot these functions with the follow-ing MATLAB script. The plot is shown in Figure 3.3.

    x=-3:0.01:3; y=x; z=x.^2+y.^2;...w=5+2.*(x −1)+4.*(y −2);...plot(x,z,x,w); grid

    Figure 3.3. An example of linearization at a specified point

    MATLAB provides three functions to extract linear functions in the form of state −space matrices, , , and . We recall that the input −output relationship in terms of these matrices is

    (3.3)

    where represents the state(s), the input, and the output, and the inputs and outputs mustbe Inport and Outport blocks. Other blocks cannot be used as inputs and outputs.

    Example 3.2

    We will use the MATLAB linmod(‘x’) function to extract the linear model for the model shownin Figure 3.4.

    We save the given model as Figure_3_4, and in MATLAB’s Command Window we execute thecommand [A,B,C,D]=linmod('Figure_3_4'). MATLAB displays the four matrices as

    a b ,( ) xa b ,( ) y a b ,( )

    z f x y,( ) x2 y2+= = 1 2 ,( )

    w L 1 2,( ) 5 2 x 1–( ) 4 y 2–( )+ += = x y

    A B C D

    x· Ax Bu+=

    y Cx Du+=

    x u y

  • 8/9/2019 BAB03- The Cont Blocks Lib

    5/20

    Introduction to Simulink with Engineering Applications 3−5Copyright© Orchard Publications

    The Continuous −Time Linear Systems Sub −Library

    Figure 3.4. Model for Example 3.2

    A =

    - 5 - 6 - 1

    1 0 0

    0 1 - 2

    B =

    1

    0 0

    C =

    0 1 0

    D =

    0

    and thus the model of Figure 3.4 can be represented as

    The Simulink Extras library contains the Switched derivative for linearization block and theSwitched transport delay for linearization block. The former should be used in place of thederivative when we are linearizing the model. It approximates the derivative with a proper trans-fer function. The latter delays the input by a specified amount of time. It can be used to simulate a

    time delay.To avoid possible problems with derivatives we can incorporate the derivative block in otherblocks.

    Example 3.3

    Let us consider the model of Figure 3.5.

    x·5– 6– 1–1 0 00 1 2–

    x100

    u+=

    y 0 1 0 x 0 u+=

  • 8/9/2019 BAB03- The Cont Blocks Lib

    6/20

    Chapter 3 The Continuous Blocks Library

    3−6 Introduction to Simulink with Engineering Applications Copyright© Orchard Publications

    Figure 3.5. Model with derivative block

    Recalling that differentiation in the time domain corresponds to multiplication by in the com-

    plex frequency domain minus the initial value of at , that is,

    and assuming that the initial value is zero, we can replace the model of Figure 3.5 with that of Fig-ure 3.6.

    Figure 3.6. Model equivalent to the model of Figure 3.5

    3.1.3 The State −Space Block

    The State-Space block implements a system defined by the state −space equations

    (3.4)

    where and are column vectors, matrix must be an square matrix where representsthe number of the states, matrix must have dimension where represents the numberof inputs, matrix must have dimension where represents the number of outputs, andmatrix must have dimension .

    For examples with the state −space block please refer to Chapter 1, Examples 1.1 and 1.2.3.1.4 The Transfer Fcn Block

    s

    f t( ) t 0 −=

    f ' t( ) ddt----- f t( )= sF s( ) f 0 −( )–⇔

    x· Ax Bu+=

    y Cx Du+=

    x u A n n× n

    B n m× m

    C r n× r

    D r m×

  • 8/9/2019 BAB03- The Cont Blocks Lib

    7/20

    Introduction to Simulink with Engineering Applications 3−7Copyright© Orchard Publications

    The Continuous −Time Linear Systems Sub −Library

    The Transfer Fcn block implements a transfer function where the input and output can be expressed in transfer function form as the following equation

    (3.5)

    Example 3.4

    Let us consider the op amp circuit of Figure 3.7.

    Figure 3.7. Circuit for Example 3.3 to be simulated.

    It can be shown * that the transfer function of the op amp circuit of Figure 3.7 is given by

    (3.6)

    and this transfer function describes a second order lowpass filter. For simplicity, we let

    and by substitution of these values into (3.6) we obtain

    (3.7)

    Assuming that the input is the unit step function, we will create a model using the Trans-

    fer Fcn block to simulate the output .

    The model is shown in Figure 3.8 where in the Function Block Parameters dialog box for theTransfer Fcn block we have entered for the numerator and for the denominator.

    * The derivation of this transfer function is shown in Chapter 4, Signals and Systems with MATLAB Applica-tions, ISBN 0-9709511-6-7.

    V in s( )

    V ou t s( )

    G s( )V ou t s( )V in s( )

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

    R2

    1/sC 1

    R3R11/sC 2

    Vin (s)Vout (s)

    G s( )V ou t s( )V in s( )

    ------------------ 1–

    R 1 1 R 1 ⁄ 1 R 2 ⁄ 1 R 3 ⁄ sC 1+ + +( ) sR 3 C 2( ) 1 R 2 ⁄ +[ ]-----------------------------------------------------------------------------------------------------------------------------------= =

    R 1 R 2 R 3 1 Ω= = =

    C 1 C 2 1 F= =

    G s( )V ou t s( )V in s( )

    ------------------ 1–

    s2

    3+ s 1+[ ]--------------------------------= =

    V in s( )

    V ou t s( )

    1– 1 3 1[ ]

  • 8/9/2019 BAB03- The Cont Blocks Lib

    8/20

    Chapter 3 The Continuous Blocks Library

    3−8 Introduction to Simulink with Engineering Applications Copyright© Orchard Publications

    Figure 3.8. Model for Example 3.4

    Upon execution of the Simulation start command, the Scope displays the waveform shown in Fig-ure 3.9.

    Figure 3.9. Output waveform for the model of Figure 3.8

    3.1.5 The Zero −Pole Block

    The Zero-Pole block implements a system with the specified zeros, poles, and gain in the s −domain. This block displays the transfer function depending on how the parameters are specified:

    1. If each is specified as an expression or a vector, the icon shows the transfer function with thespecified zeros, poles, and gain. If we specify a variable in parentheses, the variable is evaluated.For example, if in the Function Block Parameters dialog box we specify Zeros as [2 4 6 8], Polesas [1 3 5 7 9], and Gain as 25, the block looks like as shown in Figure 3.10. *

    Figure 3.10. The Zero-Pole block specified in vector form

    * We may need to stretch the block to see the entire block shown above.

  • 8/9/2019 BAB03- The Cont Blocks Lib

    9/20

    Introduction to Simulink with Engineering Applications 3− 9Copyright© Orchard Publications

    The Continuous − Time Linear Systems Sub − Library

    2. If each is specified as a variable, e.g., zeros , poles , Gain , in MATLAB’s Command Window weenter

    zeros=[2 4 6 8]; poles=[1 3 5 7 9]; Gain=25;

    the block shows the variable name followed by (s) if appropriate. For this example the block

    appearance will be as shown in Figure 3.11.

    Figure 3.11. The Zero-Pole block specified as variables

    Example 3.5

    The system transfer function of a system has a gain factor of , zeros at , and poles atand at . We will create a model to display the step response of this system.

    The model and the input and output waveforms are shown in Figures 3.12 and 3.13 respectively.

    Figure 3.12. Model for Example 3.5

    Figure 3.13. Input and output waveforms for the model of Figure 3.12

    1.5 2– j± 3–1– j±

  • 8/9/2019 BAB03- The Cont Blocks Lib

    10/20

    Chapter 3 The Continuous Blocks Library

    3−10 Introduction to Simulink with Engineering Applications Copyright© Orchard Publications

    3.2 The Continuous −Time Delays Sub −Library

    The Continuous −Time Delays Sub −Library contains the blocks described in Subsections 3.2.1through 3.2.3 below.

    3.2.1 The Transport Delay Block

    The Transport Delay block delays the input by a specified amount of time. It can be used to sim-ulate a time delay. At the start of the simulation, the block outputs the Initial input parameteruntil the simulation time exceeds the Time delay parameter. The Time delay parameter must benonnegative. Best accuracy is achieved when the delay is larger than the simulation step size.

    Example 3.6

    For the model shown in Figure 3.14, the Time delay in the Function Block Parameters dialog boxis specified as 2, and this delay is shown in Figure 3.15.

    Figure 3.14. Model to illustrate the use of the Transport Delay block

    Figure 3.15. Input and output waveforms for the model of Figure 3.14

  • 8/9/2019 BAB03- The Cont Blocks Lib

    11/20

    Introduction to Simulink with Engineering Applications 3−11Copyright© Orchard Publications

    The Continuous −Time Delays Sub −Library

    When an output is required at a time that does not correspond to the times of the stored inputvalues, the Transport Delay block interpolates linearly between points. For a more detailed dis-cussion please refer to the Help menu for this block.

    The Transport Delay block does not interpolate discrete signals. Instead, it returns the discretevalue at the required time.

    3.2.2 The Variable Time Delay Block

    The Variable Time Delay block and the Variable Transport Delay block appear as two blocks inthe Simulink block library. However, they are actually the same built −in Simulink block with dif-ferent settings of a Select delay type parameter. In the Variable Time Delay mode, the block has adata input, a time delay input, and a data output. The block's output at the current time stepequals the value of its data input at a previous time which is equal to the current simulation timeminus a delay time specified by the block's time delay input.

    Example 3.7

    The model in Figure 3.16 shows a Variable Time Delay block where the Signal Generator blockoutput is a square wave and the Constant block is set to the value 0.5 to introduce a delay of 0.5second. The input and output of the Variable Time Delay block are shown in Figure 3.17.

    Figure 3.16. Model with Variable Time Delay

  • 8/9/2019 BAB03- The Cont Blocks Lib

    12/20

    Chapter 3 The Continuous Blocks Library

    3−12 Introduction to Simulink with Engineering Applications Copyright© Orchard Publications

    Figure 3.17. Signal Generator block and Variable Time Delay block for the model of Figure 3.16

    3.2.3 The Variable Transport Delay Block

    In the Variable Transport Delay block the output is equal to the value of its data input at an ear-lier time which is equal to the current time minus a transportation delay. If we let be theinput, the transportation delay, and the output, then

    (3.8)

    Example 3.8

    From electric circuit theory, we know that an alternating current through a capacitor leadsthe voltage by . Using a Variable Transport Delay block, we will create a model that willdisplay the current and voltage waveforms.

    The model and the input and output waveforms are shown in Figures 3.18 and 3.19 respectively.

    Figure 3.18. Model for Example 3.8

    u t ( )t d t ( ) y t ( )

    y u t td t( )–( )=

    iC C

    vC 90°

  • 8/9/2019 BAB03- The Cont Blocks Lib

    13/20

    Introduction to Simulink with Engineering Applications 3−13Copyright© Orchard Publications

    The Continuous −Time Delays Sub −Library

    Figure 3.19. Input and output waveforms for the model of Figure 3.18

  • 8/9/2019 BAB03- The Cont Blocks Lib

    14/20

    Chapter 3 The Continuous Blocks Library

    3−14 Introduction to Simulink with Engineering Applications Copyright© Orchard Publications

    3.3 Summary

    • The Integrator block outputs the integral of its input at the current time step.

    • The Derivative block approximates the derivative of its input. The block accepts one inputand generates one output. The initial output for the block is zero. For nonlinear models, wecan use the MATLAB function linmod to linearize a model that contains a Derivative block.To avoid problems, it is recommended that before linearizing we replace troublesome blockswith blocks found in the Simulink Extras library in the Linearization sublibrary. To avoid possi-ble problems with derivatives we can incorporate the derivative block in other blocks.

    • MATLAB provides three functions to extract linear functions in the form of state-space matri-ces , , , and . The input-output relationship in terms of these matrices is

    where represents the state(s), the input, and the output, and the inputs and outputsmust be Inport and Outport blocks. Source and Sink blocks cannot be used as inputs and out-puts.

    • The Simulink Extras library contains the Derivative for linearization block and the TransportDelay block. The former should be used in place of the derivative when we are linearizing themodel. It approximates the derivative with a proper transfer function. The latter delays theinput by a specified amount of time. It can be used to simulate a time delay.

    • The State-Space block implements a system defined by the state-space equations

    where and are column vectors, and must be matrices conformable for multiplicationwith , and and must be matrices conformable for multiplication with .

    • The Transfer Fcn block implements a transfer function where the input and output (y)can be expressed in transfer function form as the following equation

    • The Zero-Pole block implements a system with the specified zeros, poles, and gain in the s-domain. The Zero-Pole block displays the transfer function depending on how the parametersare specified. If each is specified as an expression or a vector, the icon shows the transfer func-tion with the specified zeros, poles, and gain. If we specify a variable in parentheses, the vari-able is evaluated.

    A B C D

    x· Ax Bu+=

    y Cx Du+=

    x u y

    x· Ax Bu+=

    y Cx Du+=

    x u A C

    x B D u

    V in s( )

    G s( )V

    ou t s( )

    V in s( )------------------=

  • 8/9/2019 BAB03- The Cont Blocks Lib

    15/20

    Introduction to Simulink with Engineering Applications 3−15Copyright© Orchard Publications

    Summary

    • The Transport Delay block delays the input by a specified amount of time. It can be used tosimulate a time delay. At the start of the simulation, the block outputs the Initial input param-eter until the simulation time exceeds the Time delay parameter, when the block begins gener-ating the delayed input. The Time delay parameter must be nonnegative. Best accuracy isachieved when the delay is larger than the simulation step size.

    • The Variable Time Delay block and the Variable Transport Delay block appear as two blocksin the Simulink block library. However, they are actually the same built-in Simulink block withdifferent settings of a Select delay type parameter. In the Variable Time Delay mode, the blockhas a data input, a time delay input, and a data output. The block's output at the current timestep equals the value of its data input at a previous time equal to the current simulation timeminus a delay time specified by the block's time delay input.

    • In the Variable Transport Delay block the output at the current time step is equal to thevalue of its data input at an earlier time equal to the current time minus a transportation delay.If we let be the input, the transportation delay, and the output, then

    u t ( ) t d t ( ) y t ( )

    y u t td t( )–( )=

  • 8/9/2019 BAB03- The Cont Blocks Lib

    16/20

    Chapter 3 The Continuous Blocks Library

    3−16 Introduction to Simulink with Engineering Applications Copyright© Orchard Publications

    3.4 Exercises

    1. Using MATLAB’s linmod(‘x’) function, express the model below in state −space form.

    2. Create a model that includes a Transfer Fcn block to simulate the output of the circuit

    below where represents the internal resistance of the applied (source) voltage , andrepresents the resistance of the load that consists of , , and . The values of the circuitconstants are , , , and .

    3. From electric circuit theory, it is known that charging a capacitor with a constant current pro-duces a linear voltage across it, that is,

    where is the capacitance in farads, is the constant current through the capacitor in

    amperes, and is the linear voltage across the capacitor in volts. Using a Variable TransportDelay block create a model to display the output if , , and the voltageacross the capacitor at some time is .

    vou t

    R g v g R LR L L C

    R g 100 Ω= R L 1 K Ω= L 10 mH= C 500 µ F=

    +

    R g

    R L

    L

    C

    vou t

    v g

    V CIC---- t=

    C I

    V C

    I 2 mA= C 1000 µ F=t 0 V 0 2 v=

  • 8/9/2019 BAB03- The Cont Blocks Lib

    17/20

    Introduction to Simulink with Engineering Applications 3−17Copyright© Orchard Publications

    Solutions to End −of −Chapter Exercises

    3.5 Solutions to End −of −Chapter Exercises

    1. The first step is to replace the source and sink blocks with Inport and Outport blocks as shownbelow. This model is saved as Exercise_3_1A .

    From MATLAB’s Command Window we execute the statement

    [A,B,C,D]=linmod('Exercise_3_1A')

    and MATLAB displays

    A =

    3 0

    10 -1

    B =

    1

    0

    C =

    1 0 0 1

    D =

    0

    0

    Therefore, the linear model of the given model in state-space form is expressed as

    x· 3 010 1–

    x 10

    u+=

    y 1 00 1

    x 00

    u+=

  • 8/9/2019 BAB03- The Cont Blocks Lib

    18/20

    Chapter 3 The Continuous Blocks Library

    3−18 Introduction to Simulink with Engineering Applications Copyright© Orchard Publications

    2.The equivalent circuit is shown below.

    The transfer function is readily found by application of the voltage division expression

    Then,

    With , , , and , the transfer function

    becomes

    This transfer function is very nearly unity for all values of the variable and thus we expectthe output to be the same as the input. In the model shown below, the Signal Generator’s

    waveform was chosen as sawtooth with amplitude and frequency 0.25 Hz.

    s do main–

    +

    −V in s( )

    R g

    R L

    sL

    1sC------

    V ou t s( )

    G s( )

    V ou t s( )R L sL 1 sC ⁄ + +

    R g R L sL 1 sC ⁄ + + +---------------------------------------------------- V in s( )=

    G s( )V out s( )V in s( )------------------=

    R L Ls 1 sC ⁄ + +

    R g R L Ls 1 sC ⁄ + + +----------------------------------------------------=

    G s( )Vout s( )V in s( )------------------=

    LCs 2 R LCs 1+ +

    LCs 2 R g R L+( )Cs 1+ +------------------------------------------------------------=

    R g 100 Ω= R L 1 K Ω= L 10 mH= C 500 µF=

    G s( )V ou t s( )V in s( )------------------= 5 10

    6– s2× 5 10 4–

    s× 1+ +

    5 10 6–

    s2× 5.5 10 4–

    s× 1+ +--------------------------------------------------------------------=

    G s( )Vout s( )V in s( )------------------= s

    2 500s 2 10 5×+ +

    s2 550s 2 10 5×+ +----------------------------------------------=

    s

    2

  • 8/9/2019 BAB03- The Cont Blocks Lib

    19/20

    Introduction to Simulink with Engineering Applications 3− 19Copyright© Orchard Publications

    Solutions to End − of − Chapter Exercises

    3.

    . Then

    For

    The model and the input and output are shown below where the slope for the Ramp block isset to 2 and the time delay of 1 second is specified by the Constant block.

    V CIC---- t 2 10 3× t= =

    Slope m I C ⁄ = =

    m IC---- 2 10

    3–×

    10 3–

    -------------------- 2= = =

    V CIC---- t 2t= =

    V C V 0 2 v= =

    t t 022--- 1 s= = =

  • 8/9/2019 BAB03- The Cont Blocks Lib

    20/20

    Chapter 3 The Continuous Blocks Library

    3 20 I t d ti t Si li k ith E gi i g A li ti