50469323 MATLAB Basics for SISO LTI Systems

Embed Size (px)

Citation preview

  • 8/4/2019 50469323 MATLAB Basics for SISO LTI Systems

    1/6

    MATLAB basics for SISO LTI systems

    SYSTEM REPRESENTATION

    MATLAB defines systems in 3 ways

    1) Transfer functions can be formed in the following waysNOTE: Polynomials in MATLAB are represented as a vector.

    a) >> num = [1 5];>> den = [1 4 5];

    >> sys = tf(num,den)

    Transfer function:

    s + 5

    -------------

    s^2 + 4 s + 5

    b) >> sys = tf([1 5],[1 4 5])Transfer function:

    s + 5

    -------------

    s^2 + 4 s + 5

    c) You can also create an LTI object as follows>> s=tf('s')

    Now, this object can be arithmetically manipulated to create the transfer function as follows:>> sys = (s+5)/(s^2+4*s+5)

    Transfer function:

    s + 5

    -------------

    s^2 + 4 s + 5

    2) State Variable RepresentationThe state space representation of a system can be represented as follows:

    = + = + Example: Consider the following linear differential equations:

    = + 2 = 3 + 5

    = Where and are the states

    is the output is the input

  • 8/4/2019 50469323 MATLAB Basics for SISO LTI Systems

    2/6

    = 1 20 3

    + 03

    = 1 0 + 0To create this system in MATLAB:

    >> A = [-1 2;0 -3];

    >> B = [0;3];

    >> C = [1 0];

    >> D = 0;

    >> sys = ss(A,B,C,D)

    a =x1 x2

    x1 -1 2

    x2 0 -3

    b =

    u1

    x1 0

    x2 3

    c =

    x1 x2

    y1 1 0

    d =

    u1

    y1 0

    Continuous-time model.

    3) Zero-Pole-GainTransfer functions can be given in the following form:

    = 4 + 3 +5 + 1 + 2 +3

    This can be created in MATLAB using the zpkcommand:

  • 8/4/2019 50469323 MATLAB Basics for SISO LTI Systems

    3/6

    >> Z = [-3 -5];

    >> P = [-1 -2 -3];

    >> K = 4;

    >> sys = zpk(Z,P,K)

    Zero/pole/gain:

    4 (s+3) (s+5)

    -----------------

    (s+1) (s+2) (s+3)

    >> sys = zpk([-3 -5],[-1 -2 -3],[4])

    Zero/pole/gain:

    4 (s+3) (s+5)

    -----------------

    (s+1) (s+2) (s+3)

    POLE-ZERO CANCELLATION

    To cancel any common poles and zeros in a transfer function, you can use the command.Example:

    >> sys = tf([1 3],[1 3 0])

    Transfer function:s + 3

    ---------

    s^2 + 3 s

    >> minreal(sys)

    Transfer function:

    1

    -

    s

    DATA EXTRACTION

    For quick access to the numerator and denominator of the transfer function of an LTI system

    [num,den] = tfdata(sys) returns the numerator and denominator of the transfer function sys.NOTE: For a single SISO model,

    [num,den] = tfdata(sys,'v')This command returns the numerator and denominator as row vectors rather than cell arrays.

    For access to A,B,C,D matrices of an LTI system, the following syntax may be used:

    [A,B,C,D] = ssdata(sys)To extract information of the zeros, poles and gain of an LTI system the following syntax can be used:

  • 8/4/2019 50469323 MATLAB Basics for SISO LTI Systems

    4/6

    [Z,P,K] = zpkdata(sys)Again, [Z,P,K] = ZPKDATA(SYS,'v') returns the zeros Z and poles P as column vectors rather than cell

    arrays.

    CONVERSION

    A system in one of the three representations can be converted to any other using the following syntax:

    [input_arguments] = conversion_command [ouput_arguments]

    From To Command Input Output

    State Space Transfer function ss2tf [A,B,C,D] [num,den]

    State Space Zero-Pole-Gain ss2zp [A,B,C,D] [z,p,k]

    Transfer function State Space tf2ss [num,den] [A,B,C,D]

    Transfer function Zero-Pole-Gain tf2zp [num,den] [z,p,k]

    Zero-Pole-Gain Transfer function zp2tf [z,p,k] [num,den]Zero-Pole-Gain State Space zp2ss [z,p,k] [A,B,C,D]

    If a system is already defined, they can be automatically converted as follows:

    >> P_ss = ss(sys);

    >> P_tf = tf(sys);

    >> P_zp = zpk(sys);

    SYSTEM CONNECTIONS

    Series

    >> G1 = tf([1 3],[1 3 2]);

    >> G2 = tf([1],[5 3]);

    >> G = G2*G1

    Transfer function:

    s + 3-------------------------

    5 s^3 + 18 s^2 + 19 s + 6

    >> G = series(G1,G2)

    Transfer function:

    s + 3

    -------------------------

    5 s^3 + 18 s^2 + 19 s + 6

    G1 G2G

  • 8/4/2019 50469323 MATLAB Basics for SISO LTI Systems

    5/6

    Parallel

    >> G = G1+G2

    Transfer function:

    6 s^2 + 21 s + 11

    -------------------------

    5 s^3 + 18 s^2 + 19 s + 6

    >> G = parallel(G1,G2)

    Transfer function:

    6 s^2 + 21 s + 11

    -------------------------

    5 s^3 + 18 s^2 + 19 s + 6

    Feedback

    G1

    G2

    +

    +

    G

    G1

    G2

    +

    -

  • 8/4/2019 50469323 MATLAB Basics for SISO LTI Systems

    6/6

    >> feedback(G1,G2)

    Transfer function:

    5 s^2 + 18 s + 9

    -------------------------

    5 s^3 + 18 s^2 + 20 s + 9

    >> G1/(1+G2*G1)

    Transfer function:

    5 s^4 + 33 s^3 + 73 s^2 + 63 s + 18

    ---------------------------------------------

    5 s^5 + 33 s^4 + 84 s^3 + 105 s^2 + 67 s + 18

    >> minreal(ans)

    Transfer function:

    s^2 + 3.6 s + 1.8

    -------------------------

    s^3 + 3.6 s^2 + 4 s + 1.8

    Note that the feedback function cancels the common poles and zeros whereas you have to use the

    minreal command if you use direct arithmetic operations on the transfer functions.

    SOME USEFUL COMMANDS

    conv: When A and B are vectors of polynomial coefficients, conv(A,B) results in the product of the two

    polynomials.

    poly: poly(V), when V is a vector whose elements are the coefficients of the polynomial whose roots are

    the elements of V .

    roots: roots(C) computes the roots of the polynomial whose coefficients are the elements of the vector

    C.