20
1 TRANSFER FUNCTION http://www.me.cmu.edu/ctms/modeling/tutorial/transferfunction/ mainframes.htm The modeling equation gathered from the free body diagram is in the time domain. Some analysis is easier to perform in the frequency domain. In order to convert to the frequency domain, apply the Laplace Transform to determine the transfer function of the system. The Laplace Transform converts linear differential equations into algebraic expressions which are easier to manipulate. The Laplace Transform converts functions with a real dependent variable (such as time) into functions with a complex dependent variable (such as frequency, often represented by s). The transfer function is the ratio of the output Laplace Transform to the input Laplace Transform assuming zero initial conditions. Many important characteristics of dynamic or control systems can be determined from the transfer function. The general procedure to find the transfer function of a linear differential equation from input to output is to take the Laplace Transforms of both sides assuming zero conditions, and to solve for the ratio of the output Laplace over the input Laplace. HOW TO FIND THE TRANSFER FUNCTION In most cases the governing equation will be linear, consisting of a variable and its derivatives. The Laplace Transform allows a linear equation to be converted into a polynomial. The most useful property of the Laplace Transform for finding the transfer function is the differentiation theorem. Several properties are shown below: Time Domain Frequency Domain Linearity f(t) + g(t) F ( s ) +G ( s) Function x(t) X ( s) 1 st Derivative x'(t) sX ( s ) x( 0) 2 nd Derivative x"(t) s 2 X ( s) sX ( 0) x ' ( 0 ) n th Derivative x n (t) s n X ( s) i=1 n s ( ni ) x (i1) ( 0)

Laplace Con Matlab

Embed Size (px)

Citation preview

Page 1: Laplace Con Matlab

1

TRANSFER FUNCTIONhttp://www.me.cmu.edu/ctms/modeling/tutorial/transferfunction/mainframes.htm

The modeling equation gathered from the free body diagram is in the time domain.  Some analysis is easier to perform in the frequency domain.  In order to convert to the frequency domain, apply the Laplace Transform to determine the transfer function of the system.

The Laplace Transform converts linear differential equations into algebraic expressions which are easier to manipulate.  The Laplace Transform converts functions with a real dependent variable (such as time) into functions with a complex dependent variable (such as frequency, often represented by s). 

The transfer function is the ratio of the output Laplace Transform to the input Laplace Transform assuming zero initial conditions.  Many important characteristics of dynamic or control systems can be determined from the transfer function. 

The general procedure to find the transfer function of a linear differential equation from input to output is to take the Laplace Transforms of both sides assuming zero conditions, and to solve for the ratio of the output Laplace over the input Laplace.

HOW TO FIND THE TRANSFER FUNCTION

In most cases the governing equation will be linear, consisting of a variable and its derivatives.  The Laplace Transform allows a linear equation to be converted into a polynomial.  The most useful property of the Laplace Transform for finding the transfer function is the differentiation theorem.  Several properties are shown below:

Time Domain Frequency Domain

Linearity f(t) + g(t) F ( s )+G(s)

Function x(t) X (s)

1st Derivative x'(t) sX (s )−x (0)

2nd Derivative x"(t) s2 X (s )−sX (0 )−x ' (0)

nth Derivative xn(t) sn X (s )−∑i=1

n

s(n−i) x (i−1)(0)

Note:  While linearity allows Laplace Transforms to be added, the same does not hold true for multiplication.  f(t)g(t) does not equal F(s)G(s).  The solution to multiplication requires convolution, please refer to a differential equations book.

In order to convert the time dependent governing equation to the frequency domain, perform the Laplace Transform to the input and output functions and their derivatives.  These transformed functions must then be substituted back into the governing equation assuming zero initial conditions.  Because the transfer function is defined as the output Laplace function over the input Laplace function, rearrange the equation to fit this form.

EXAMPLE

Page 2: Laplace Con Matlab

2

Find the transfer function of the second order tutorial example problem:

From the free body diagram we were able to extract the following governing equation:

f(t) - kx - bx' - mx" = 0

The notation of the Laplace Transform operation is L{ }.

When finding the transfer function, ‘zero’ initial conditions must be assumed, so x(0) = x'(0) = 0.

Taking the Laplace Transform of the governing equation results in:

F(s) - k[X(s)] - b[sX(s)] - m[s2X(s)] = 0

Collecting all the terms involving X(s) and factoring leads to:

[ms2 + bs + k] X(s) = F(s)

The transfer function is defined as the output Laplace Transform over the input Laplace Transform, and so the transfer function of this second order system is:

X(s)/F(s) = 1/[ms2 + bs + k]

HOW TO INPUT THE TRANSFER FUNCTION INTO MATLAB

In order to enter a transfer function into MATLAB, the variables much be given numerical value, because MATLAB cannot manipulate symbolic variables without the symbolic toolbox.  Enter the numerator and denominator polynomial coefficients separately as vectors of coefficients of the individual polynomials in descending order.   The syntax for defining a transfer function in MATLAB is:

transferfunction = tf(num, den)

where num is defined as the vector of numerator coefficients, and den is defined as the vector of denominator coefficients.

EXAMPLE

Input the transfer function X(s)/F(s) = 1/[ms2 + bs + k] into MATLAB:

For illustration purposes, this example uses m = 2, b = 5, and k = 3.

>> m = 2;>> b = 5;>> k = 3;>> num = [ 1 ];>> den = [ m b k ];>> tutorial_tf = tf(num, den)

MATLAB will assign the transfer function under the name tutorial_tf, and output the

following:

Page 3: Laplace Con Matlab

3

Transfer function:       1---------------2 s^2 + 5 s + 3

STEP RESPONSE USING THE TRANSFER FUNCTION

Once the transfer function is entered into MATLAB it is easy to calculate the response to a step input.  To calculate the response to a unit step input, use:

step(transferfunction)

where transferfunction is the name of the transfer function of the system.

For steps with magnitude other than one, calculate the step response using:

step(u * transferfunction)

where u is the magnitude of the step and  transferfunction is the name of the transfer

function of the system.

EXAMPLE

Find the unit step response and the step response when u = 4 of  tutorial_tf using

MATLAB:

To find the unit step response:

>> step(tutorial_tf)

The MATLAB output will be the following plot of the unit step response:

Page 4: Laplace Con Matlab

4

To find the step response when u = 4:

>> u = 4;

>> step(u * tutorial_tf)

The MATLAB output will be the following plot of the step response:

Page 5: Laplace Con Matlab

5

IMPULSE RESPONSE USING THE TRANSFER FUNCTION 

MATLAB can also plot the impulse response of a transfer function.  Because the transfer function is in the form of output over input, the transfer function must be multiplied by the magnitude of the impulse.  The syntax for plotting the impulse response is: 

impulse(u * transferfunction)

where u is the magnitude of the impulse and  transferfunction is the name of the

transfer function of the system.

EXAMPLE

Find the impulse response of  tutorial_tf with an input of u = 2 using MATLAB:

>> u = 2;

>> impulse(u * tutorial_tf)

The MATLAB output will be the following plot of the impulse response:

BODE PLOT USING THE TRANSFER FUNCTION

MATLAB’s bode command plots the frequency response of a system as a bode plot.  The syntax for the bode plot function in MATLAB is:

bode(transferfunction)

where transferfunction is the name of the transfer function system.

Page 6: Laplace Con Matlab

6

EXAMPLE

Find bode plot of the frequency response of the system tutorial_tf using MATLAB:

>> bode(tutorial_tf)

The MATLAB output will be the following bode plot of the frequency response:

STATE SPACE FROM TRANSFER FUNCTION

MATLAB can find the state space representation directly from the transfer function in two ways.  To find the state space representation of the system from the numerator and denominator of the transfer function in the form

x' = Ax + Bu

y = Cx + Du

use MATLAB's tf2ss command:

[A, B, C, D] = tf2ss(num,den)

where num is the vector of the numerator polynomial coefficients, and den is the vector of the denominator polynomial coefficients.

In order to find the entire state space system in addition to the separate matrices from the transfer function, use the following command:

statespace = ss(transferfunction)

Page 7: Laplace Con Matlab

7

where transferfunction is the name of the transfer function system.

EXAMPLE

Find A, B, C, and D, the state space vectors of  tutorial_tf using MATLAB:

>> [A, B, C, D] = tf2ss(num,den)

The MATLAB output will be:

A =    -2.5000   -1.5000    1.0000         0B =     1     0C =     0    0.5000D =     0

Find the state space system of  tutorial_tf using MATLAB:

>> tutorial_ss = ss(tutorial_tf)

MATLAB will assign the state space system under the name tutorial_ss, and output the

following:

a =           x1      x2   x1    -2.5  -0.375   x2       4       0 b =         u1   x1  0.25   x2     0 c =        x1   x2   y1    0  0.5 

d =       u1   y1   0 Continuous-time model.

http://antiguo.itson.mx/die/jmurrieta/cursos/se%C3%B1alesysistemas/tutorial%20Laplace-matlab.pdfhttp://www.seas.upenn.edu/~ese216/handouts/Chpt13LaplaceTransformsMATLAB.pdf

Page 8: Laplace Con Matlab

8

Tutorial de Matlab (1ra Parte)Operaciones básicas del análisis matemático

Derivadas: Para realizar derivadas utilizando MatLab usaremos el comando diff.

>> diff('x^2')ans = 2x>> diff ('x^2',2) "Calculo de la 2da derivada"ans = 2

Para el calcular, 2da derivada, 3ra deriva hasta n derivada el comando será: diff(' ',n).

Integrales: Para realizar calculo integral usaremos el comando int.

Integrales Indefinidas

>> int('2x')ans = x^2

Integrales Definidas

>> int('x',1,3)ans = 4

Transformada de Laplace: Para realizar transformadas de Laplace tenemos que usar variable simbólicas.

>> syms x t s w>> laplace (sin(3*t))ans = 3/s^2+9

Calculo de raíces de un polinomio: Para realizar cálculo de raíces de cualquier polinomio usaremos el comando roots de la siguiente manera:

Sea el polinomio x^2 -5x +6=0, calcular las raíces del mismo.

1ro. Tomamos los coeficientes del polinomio: 1 -5 6

2do. Utilizamos el comando roots

>> roots([1 -5 6])ans =x= -3x= -2

Nota: Al introducir los coeficientes dentro del comando, los separamos con un espacio.

Creación de un polinomio a partir de sus raíces: Para crear un polinomio a partir de sus raíces usaremos el comando poly de la siguiente manera:

Usando las raíces del polinomio anterior.

Page 9: Laplace Con Matlab

9

>> poly([-3 -2])ans = x^2-5x+6

Tutorial de MATLAB II Parte (Transformada de Laplace)

La Transformada de Laplace de una función f(t) para todos los números reales mayores o iguales al cero es la función F(s) definida por:

F ( s )=L [ f ( t ) ]=∫0

f (t )e− st dt

Esta transformada integral tiene una serie de propiedades que la hacen útil en el análisis de sistemas lineales. Una de las ventajas más significativas radica en que la integración y derivación se convierten en multiplicación y división. Esto transforma las ecuaciones diferenciales e integrales en ecuaciones polinómicas, mucho más fáciles de resolver.

Es importante recordar que para el uso de la Transformada de Laplace en

MatLab se necesitará trabajar con variables simbólicas.

A través de MatLab podemos realizar el calculo este tipo de transformada de una manera muy sencilla. Los comandos a utilizar son los siguientes:

laplace( ) : Comando para realizar Transformadas de Laplace.

>> laplace(sin(t))ans=1/(s^2+1)

ilaplace( ) : Comando para realizar la Transformada Inversa de Laplace

>> ilaplace(1/s(s^2+1))ans=sin(t)

dirac( ) : Comando para realizar Transformadas de Laplace cuya f(t) tiene como argumento una

función impulso o Delta de Dirac.

>> laplace(dirac(t))ans=1

heaviside( ) : Comando para realizar Transformadas de Laplace cuya f(t) tiene como argumento

una función escalón.

>> laplace(heaviside(t-5))

ans=exp(-5*s)/s

Es importante recordar que para el uso de la Transformada de Laplace en MatLab se necesitará trabajar con variables simbólicas.

Ejercicio 

f ( t )={ 4 t si0<t<15−t si1≤t ≤5

Page 10: Laplace Con Matlab

10

1er Metodo. Desarrollando toda la expresión y aplicar la propiedad de Linealidad a la expresión.

>>laplace(4*t*heaviside(t))-laplace(4*t*heaviside(t-1))+laplace((5-t)* heaviside(t-1))-laplace((5-t)*heaviside(t-5))

ans=

4/s^2-5*exp(-s)/s^2 + exp(-5*s)/s^2

2do Metodo. Aplicando Transformada de Laplace a toda la expresión directamente si

desarrollarla.

>> laplace(4*t*(heaviside(t)-heaviside(t-1))+(5-t)*(heaviside(t-1)-heaviside(t-5)))

ans=

4/s^2-5*exp(-s)/(s^2+exp(-5*s)/s^2

LAPLACE TRANSFORMlaplace -

Syntax

laplace(F)

laplace(F,t)

laplace(F,w,z)

Description

L = laplace(F) computes the Laplace transform of the symbolic expression F. This

syntax assumes that F is a function of the variable t, and the returned value L as a function of s.

F=F ( t )⇒ L=L(s)

If F = F(s), laplace returns a function of t.L = L (t)By definition, the Laplace transform is

L (s )=∫0

F (t)e−st dt

L = laplace(F,t) computes the Laplace transform L as a function of t instead of the

default variable s.

L (t )=∫0

F (x )e−tx dx

L = laplace(F,w,z) computes the Laplace transform L and lets you specify that L is a

function of z and F is a function of w.

Page 11: Laplace Con Matlab

11

L ( z)=∫0

F(w)e−zwdw

Examples

Laplace Transform MATLAB Command

f (t)=t 4

L[ f ]=∫0

f (t)e−tsdt

¿ 24s5

>> syms t;>> f = t^4;>> laplace(f)returns

ans =24/s^5

g (s )= 1

√s

L [g ](t )=∫0

g(s)e−st ds

¿√ πt

>> syms s;>> g = 1/sqrt(s);>> laplace(g)returnsans =pi^(1/2)/t^(1/2)

f (t )=e−at

L [ f ] (x)=∫0

f ( t)e−tx dt

¿ 1x+a

>> syms t a x;>> f = exp(-a*t);>> laplace(f,x)returnsans =1/(a + x)

INVERSE LAPLACE TRANSFORMilaplace -

Syntax

F = ilaplace(L)F = ilaplace(L,y)F = ilaplace(L,y,x)

Description

F = ilaplace(L) computes the inverse Laplace transform of the symbolic expression L.

This syntax assumes that L is a function of the variable s, and the returned value F is a function of t.

L=L (s )⇒F=F( t)

If L = L(t), ilaplace returns a function of x.F = F (x)By definition, the inverse Laplace transform is

Page 12: Laplace Con Matlab

12

F ( t )= 12πi

∫c−i∞

c+i∞

L(s)est ds

where c is a real number selected so that all singularities of L(s) are to the left of the line s = c, i.

F = ilaplace(L,y) computes the inverse Laplace transform F as a function of y instead

of the default variable t.

F ( y )= 12 πi

∫c−i∞

c+i∞

L( y)esy ds

F = ilaplace(L,y,x) computes the inverse Laplace transform and lets you specify

that F is a function of x and L is a function of y.

F ( x )= 12πi

∫c−i∞

c+i∞

L( y)exy dy

Examples

Inverse Laplace Transform MATLAB Command

f ( s )= 1s2

L−1 [ f ]= 12πi

∫c−i∞

c+i∞

f (s)est ds

= t

>> syms s;>> f = 1/s^2;>> ilaplace(f)returns ans = t

g (t )= 1

(t−a)2

L−1 [g ]= 12 πi

∫c−i∞

c+i∞

g (t)ext dt

¿ x eax

>> syms a t;>> g = 1/(t-a)^2;>> ilaplace(g)returns ans = x*exp(a*x)

f (u )= 1

u2−a2

L−1 [ f ]= 12πi

∫c−i∞

c+i∞

g(u)exudu

¿sinh(xa)a

>> syms x u;>> syms a real;>> f = 1/(u^2-a^2);>> simplify(ilaplace(f,x))returns ans = sinh(a*x)/a

Example 1.

Find the Laplace transform of

Page 13: Laplace Con Matlab

13

f ( t )=5e−2 t

Matlab performs Laplace transform symbolically. Thus, you need to first define the variable t as a "symbol".

>> syms t

Next, enter the function f(t):

>> f=5*exp(-2*t);

Finally, enter the following command:

>> L=laplace(f)

Matlab yields the following answer:

L=

5/(s+2)

Example 2.

Find the Laplace transform of:

12d2 yd t 2

In Matlab Command Window:

>> laplace(12*diff(sym('y(t)'),2))

Note that the function y(t) is defined as symbol with the imbedded command "sym". The number 2 means we wish to take the second derivative of the function y(t).

Matlab result:

ans =

12*s*(s*laplace(y(t),t,s)-y(0))-12*D(y)(0)

where y(0) is the initial condition.

Example 3.

Find the inverse Laplace transform of

Y (s )=1s+ 2(s+4)

+ 1(s+5)

In Matlab Command window:

>> ilaplace(1/s-2/(s+4)+1/(s+5))

Matlab result:

Page 14: Laplace Con Matlab

14

ans =1-2*exp(-4*t)+exp(-5*t)

or

y (t )=(1−2e−4 t+e−5 t )u (t )

which is the solution of the differential equation

d2 yd t2

+12 dydt

+32 y=32u (t)

As an exercise, you should carry out the Laplace transform of the above differential equation with initial condition y(0) = 0 to arrive to the expression of Y(s) as shown above.

ZP2TF Zero-pole to transfer function conversion.

[NUM,DEN] = ZP2TF(Z,P,K) forms the transfer function:

H (s )= NUM (s)DEN (s)

given a set of zero locations in vector Z, a set of pole locations in vector P, and a gain in scalar K. Vectors NUM and DEN are returned with numerator and denominator coefficients in descending powers of s.

TF2ZP Transfer function to zero-pole conversion.

[Z,P,K] = TF2ZP(NUM,DEN) finds the zeros, poles, and gains:

H (s )=K ( s+z 1 ) (s+ z2 )……. (s+zm )(s+p1 ) ( s+ p2 )……. (s+ pn )

from a SIMO transfer function in polynomial form:

H (s )= NUM (s)DEN (s)

Vector DEN specifies the coefficients of the denominator in descending powers of s. Matrix NUM indicates the numerator coefficients with as many rows as there are outputs. The zero locations are returned in the columns of matrix Z, with as many columns as there are rows in NUM. The pole locations are returned in column vector P, and the gains for each numerator transfer function in vector K.

For discrete-time transfer functions, it is highly recommended to make the length of the numerator and denominator equal to ensure correct results. You can do this using the function EQTFLENGTH in the Signal Processing Toolbox. However, this function only handles single-input single-output systems.

Page 15: Laplace Con Matlab

15

RESIDUE Partial-fraction expansion (residues).

[R,P,K] = RESIDUE(B,A) finds the residues, poles and direct term of

a partial fraction expansion of the ratio of two polynomials B(s)/A(s).

If there are no multiple roots,

B (s )A (s )

=R (1 )s−P (1 )

+R (2 )s−P (2 )

+…+K (s )

Vectors B and A specify the coefficients of the numerator and denominator polynomials in descending powers of s. The residues are returned in the column vector R, the pole locations in column vector P, and the direct terms in row vector K. The number of poles is n = length(A)-1 = length(R) = length(P). The direct term coefficient vector is empty if length(B) < length(A), otherwise length(K) = length(B)-length(A)+1.

If P(j) = ... = P(j+m-1) is a pole of multiplicity m, then the expansion includes terms of the form

R ( j )s−P ( j )

+R ( j+1 )

( s−P ( j ) )2+…+

R ( j+m−1 )¿¿¿

[B,A] = RESIDUE(R,P,K), with 3 input arguments and 2 output arguments, converts the partial fraction expansion back to the polynomials with coefficients in B and A.

Warning: Numerically, the partial fraction expansion of a ratio of polynomials represents an ill-posed problem. If the denominator polynomial, A(s), is near a polynomial with multiple roots, then small changes in the data, including roundoff errors, can make arbitrarily large changes in the resulting poles and residues.

Problem formulations making use of state-space or zero-pole representations are preferable.

Class support for inputs B,A,R: float: double, single

Page 16: Laplace Con Matlab

16

Page 17: Laplace Con Matlab

17

Page 18: Laplace Con Matlab

18