tfdata

15
tfdata Quick access to transfer function data Syntax[num,den] = tfdata(sys) [num,den] = tfdata(sys,'v') [num,den,Ts] = tfdata(sys) Description[num,den] = tfdata(sys) returns the numerator(s) and denominator(s) of the transfer function for the TF, SS or ZPK model (or LTI array of TF, SS or ZPK models) sys. For single LTI models, the outputs num and den of tfdata are cell arrays with the following characteristics: num and den have as many rows as outputs and as many columns as inputs. The (i,j) entries num{i,j} and den{i,j} are row vectors specifying the numerator and denominator coefficients of the transfer function from input j to output i. These coefficients are ordered in descending powers of or . For arrays sys of LTI models, num and den are multidimensional cell arrays with the same sizes as sys. If sys is a state-space or zero- pole-gain model, it is first converted to transfer function form using tf. See Table 11-15, "LTI Properties," on page 11-194 for more information on the format of transfer function model data. For SISO transfer functions, the syntax [num,den] = tfdata(sys,'v') forces tfdata to return the numerator and denominator directly as row vectors rather than as cell arrays (see example below). [num,den,Ts] = tfdata(sys) also returns the sample time Ts. You can access the remaining LTI properties of sys with get or by direct referencing, for example, sys.Ts sys.variable ExampleGiven the SISO transfer function h = tf([1 1],[1 2 5]) you can extract the numerator and denominator coefficients by typing [num,den] = tfdata(h,'v') num = 0 1 1

Upload: muhammad-talha

Post on 24-Nov-2014

105 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: tfdata

tfdata

Quick access to transfer function data Syntax[num,den] = tfdata(sys)

[num,den] = tfdata(sys,'v')

[num,den,Ts] = tfdata(sys)

Description[num,den] =

tfdata(sys) returns the numerator(s) and denominator(s) of the transfer function for the TF, SS or ZPK model (or LTI array of TF, SS or ZPK models) sys. For single LTI models, the outputs num and den of tfdata are cell arrays with the following characteristics: num and den have as many rows as outputs and as many columns as inputs. The (i,j) entries num{i,j} and den{i,j} are row vectors specifying the numerator and denominator coefficients of the transfer function from input j to output i. These coefficients are ordered in descending powers of or . For arrays sys of LTI models, num and den are multidimensional cell arrays with the same sizes as sys. If sys is a state-space or zero-pole-gain model, it is first converted to transfer function form using tf. See Table 11-15, "LTI Properties," on page 11-194 for more information on the format of transfer function model data. For SISO transfer functions, the syntax [num,den] = tfdata(sys,'v')

forces tfdata to return the numerator and denominator directly as row vectors rather than as cell arrays (see example below). [num,den,Ts] = tfdata(sys) also returns the sample time Ts. You can access the remaining LTI properties of sys with get or by direct referencing, for example, sys.Ts

sys.variable

ExampleGiven the SISO transfer function h = tf([1 1],[1 2 5])

you can extract the numerator and denominator coefficients by typing [num,den] = tfdata(h,'v')

num =

0 1 1

den =

1 2 5

This syntax returns two row vectors. If you turn h into a MIMO transfer function by typing H = [h ; tf(1,[1 1])]

the command [num,den] = tfdata(H)

now returns two cell arrays with the numerator/denominator data for each SISO entry. Use celldisp to visualize this data. Type celldisp(num)

Page 2: tfdata

and MATLAB returns the numerator vectors of the entries of H. num{1} =

0 1 1

num{2} =

0 1

Similarly, for the denominators, type celldisp(den)

den{1} =

1 2 5

den{2} =

1 1

tf2zpk

Convert transfer function filter parameters to zero-pole-gain form Syntax[z,p,k] = tf2zpk(b,a)

Descriptiontf2zpk

finds the zeros, poles, and gains of a discrete-time transfer function. Note You should use tf2zpk when working with transfer functions expressed in inverse powers (1 + z-1 + z-2), which is how transfer functions are usually expressed in DSP. A similar function, tf2zp, is more useful for working with positive powers (s2 + s + 1), such as in continuous-time transfer functions. [z,p,k] = tf2zpk(b,a) finds the matrix of zeros z, the vector of poles p, and the associated vector of gains k from the transfer function parameters b and a: The numerator polynomials are represented as columns of the matrix b. The denominator polynomial is represented in the vector a. Given a single-input, multiple output (SIMO) discrete-time system in polynomial transfer function form you can use the output of tf2zpk to produce the single-input, multioutput (SIMO) factored transfer function form The following describes the input and output arguments for tf2zpk: The vector a specifies the coefficients of the denominator polynomial A(z) in descending powers of z. The ith row of the matrix b represents the coefficients of the ith numerator polynomial (the ith row of B(s) or B(z)). Specify as many rows of b as there are outputs. The zero locations are returned in the columns of the matrix z, with as many columns as there are rows in b. The pole locations are returned in the column vector p and the gains for each numerator transfer function in the vector k. ExamplesFind the poles, zeros, and gain of a Butterworth filter: [b,a] = butter(3,.4);

[z,p,k] = tf2zpk(b,a)

Page 3: tfdata

z =

-1.0000

-1.0000 + 0.0000i

-1.0000 - 0.0000i

p =

0.2094 + 0.5582i

0.2094 - 0.5582i

0.1584

k =

0.0985

zpkdata

Quick access to zero-pole-gain data Syntax[z,p,k] = zpkdata(sys)

[z,p,k] = zpkdata(sys,'v')

[z,p,k,Ts,Td] = zpkdata(sys)

Description[z,p,k] =

zpkdata(sys) returns the zeros z, poles p, and gain(s) k of the zero- pole-gain model sys. The outputs z and p are cell arrays with the following characteristics: z and p have as many rows as outputs and as many columns as inputs. The (i,j) entries z{i,j} and p{i,j} are the (column) vectors of zeros and poles of the transfer function from input j to output i. The output k is a matrix with as many rows as outputs and as many columns as inputs such that k(i,j) is the gain of the transfer function from input j to output i. If sys is a transfer function or state-space model, it is first converted to zero-pole-gain form using zpk. See Table 11-15, "LTI Properties," on page 11-194 for more information on the format of state-space model data. For SISO zero-pole-gain models, the syntax [z,p,k] = zpkdata(sys,'v')

forces zpkdata to return the zeros and poles directly as column vectors rather than as cell arrays (see example below). [z,p,k,Ts,Td] = zpkdata(sys) also returns the sample time Ts and the input delay data Td. For continuous-time models, Td is a row vector with one entry per input channel (Td(j) indicates by how

Page 4: tfdata

many seconds the jth input is delayed). For discrete-time models, Td is the empty matrix [] (see d2d for delays in discrete systems). You can access the remaining LTI properties of sys with get or by direct referencing, for example, sys.Ts

sys.inputname

ExampleGiven a zero-pole-gain model with two outputs and one input H = zpk({[0];[-0.5]},{[0.3];[0.1+i 0.1-i]},[1;2],-1)

Zero/pole/gain from input to output...

1

#1: -------

(z-0.3)

2 (z+0.5)

#2: -------------------

(z^2 - 0.2z + 1.01)

Sampling time: unspecified

you can extract the zero/pole/gain data embedded in H with [z,p,k] = zpkdata(H)

z =

[ 0]

[-0.5000]

p =

[ 0.3000]

[2x1 double]

k =

1

2

Page 5: tfdata

To access the zeros and poles of the second output channel of H, get the content of the second cell in z and p by typing z{2,1}

ans =

-0.5000

p{2,1}

ans =

0.1000+ 1.0000i

0.1000- 1.0000i

pzmap

Compute the pole-zero map of an LTI model Syntaxpzmap(sys)

pzmap(sys1,sys2,...,sysN)

[p,z] = pzmap(sys)

Description pzmap(sys)

plots the pole-zero map of the continuous- or discrete-time LTI model sys. For SISO systems, pzmap plots the transfer function poles and zeros. For MIMO systems, it plots the system poles and transmission zeros. The poles are plotted as x's and the zeros are plotted as o's. pzmap(sys1,sys2,...,sysN) plots the pole-zero map of several LTI models on a single figure. The LTI models can have different numbers of inputs and outputs and can be a mix of continuous and discrete systems. When invoked with left-hand arguments, [p,z] = pzmap(sys)

returns the system poles and (transmission) zeros in the column vectors p and z. No plot is drawn on the screen. You can use the functions sgrid or zgrid to plot lines of constant damping ratio and natural frequency in the - or -plane. ExamplePlot the poles and zeros of the continuous-time system. H = tf([2 5 1],[1 2 3]); sgrid

pzmap(H)

Algorithmpzmap uses a combination of pole and zero.

Dsolve

Symbolic solution of ordinary differential equations Syntaxr = dsolve('eq1,eq2,...', 'cond1,cond2,...', 'v')

r = dsolve('eq1','eq2',...,'cond1','cond2',...,'v')

Description dsolve

Page 6: tfdata

,eq2,...', 'cond1,cond2,...', 'v') symbolically solves the ordinary differential equation(s) specified by eq1, eq2,... using v as the independent variable and the boundary and/or initial condition(s) specified by cond1,cond2,.... The default independent variable is t. The letter D denotes differentiation with respect to the independent variable; with the primary default, this is d/dx. A D followed by a digit denotes repeated differentiation. For example, D2 is d2/dx2. Any character immediately following a differentiation operator is a dependent variable. For example, D3y denotes the third derivative of y(x) or y(t). Initial/boundary conditions are specified with equations like y(a) = b or Dy(a) = b, where y is a dependent variable and a and b are constants. If the number of initial conditions specified is less than the number of dependent variables, the resulting solutions will contain the arbitrary constants C1, C2,.... You can also input each equation and/or initial condition as a separate symbolic equation. dsolve accepts up to 12 input arguments. Three different types of output are possible. For one equation and one output, dsolve returns the resulting solution with multiple solutions to a nonlinear equation in a symbolic vector. For several equations and an equal number of outputs, dsolve sorts the results in lexicographic order and assigns them to the outputs. For several equations and a single output, dsolve returns a structure containing the solutions. If dsolve cannot find a closed-form (explicit) solution, it attempts to find an implicit solution. When dsolve returns an implicit solution, it issues a warning. If dsolve cannot find either an explicit or an implicit solution, then it issues a warning and returns the empty sym. In such a case, you can find a numeric solution, using the MATLAB ode23 or ode45 functions. In some cases involving nonlinear equations, the output will be an equivalent lower order differential equation or an integral. With no output arguments, dsolve returns a list of solutions. Examplesdsolve('Dy = a*x') returns C1*exp(a*t)

dsolve('Df = f + sin(t)') returns -1/2*cos(t)-1/2*sin(t)+exp(t)*C1

dsolve('(Dy)^2 + y^2 = 1','s') returns [ -1]

[ 1]

[ sin(s-C1)]

[ -sin(s-C1)]

dsolve('Dy = a*y', 'y(0) = b') returns b*exp(a*t)

dsolve('D2y = -a^2*y', 'y(0) = 1', 'Dy(pi/a) = 0') returns cos(a*t)

dsolve('Dx = y', 'Dy = -x') returns x: [1x1 sym]

y: [1x1 sym]

y = dsolve('(Dy)^2 + y^2 = 1','y(0) = 0') returns y =

sin(t)

Page 7: tfdata

-sin(t)

DiagnosticsIf dsolve cannot find an analytic solution for an equation, it prints the warning Warning: explicit solution could not be found

and return an empty sym object.

Residue

Convert between partial fraction expansion and polynomial coefficients Syntax[r,p,k] = residue(b,a)

[b,a] = residue(r,p,k)

Description

The residue function converts a quotient of polynomials to pole-residue representation, and back again. [r,p,k] = residue(b,a) finds the residues, poles, and direct term of a partial fraction expansion of the ratio of two polynomials, and , of the form where and are the jth elements of the input vectors b and a. [b,a] = residue(r,p,k) converts the partial fraction expansion back to the polynomials with coefficients in b and a. DefinitionIf there are no multiple roots, then The number of poles n 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 Argumentsb,aVectors that specify the coefficients of the polynomials in descending powers of rColumn vector of residuespColumn vector of poleskRow vector of direct termsAlgorithmIt first obtains the poles with roots. Next, if the fraction is nonproper, the direct term k is found using deconv, which performs polynomial long division. Finally, the residues are determined by evaluating the polynomial with individual roots removed. For repeated roots, resi2 computes the residues at the repeated root locations. LimitationsNumerically, the partial fraction expansion of a ratio of polynomials represents an ill-posed problem. If the denominator polynomial, , 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. ExamplesIf the ratio of two polynomials is expressed as then b = [ 5 3 -2 7]

a = [-4 0 8 3]

and you can calculate the partial fraction expansion as [r, p, k] = residue(b,a)

r =

Page 8: tfdata

-1.4167

-0.6653

1.3320

p =

1.5737

-1.1644

-0.4093

k =

-1.2500

Now, convert the partial fraction expansion back to polynomial coefficients. [b,a] = residue(r,p,k)

b =

-1.2500 -0.7500 0.5000 -1.7500

a =

1.0000 -0.0000 -2.0000 -0.7500

The result can be expressed as Note that the result is normalized for the leading coefficient in the denominator.

hold

Hold current graph in the figure Syntaxhold on

hold off

hold all

hold

hold(axes_handle,...)

Page 9: tfdata

Description

The hold function determines whether new graphics objects are added to the graph or replace objects in the graph. hold on retains the current plot and certain axes properties so that subsequent graphing commands add to the existing graph. hold off resets axes properties to their defaults before drawing new plots. hold off is the default. hold all holds the plot and the current line color and line style so that subsequent plotting commands do not reset the ColorOrder and LineStyleOrder property values to the beginning of the list. Plotting commands continue cyclicing through the predefined colors and linestyles from where the last plot stopped in the list. hold toggles the hold state between adding to the graph and replacing the graph. hold(axes_handle,...) applies the hold to the axes identified by the handle axes_handle. RemarksTest the hold state using the ishold function. Although the hold state is on, some axes properties change to accommodate additional graphics objects. For example, the axes' limits increase when the data requires them to do so. The hold function sets the NextPlot property of the current figure and the current axes. If several axes objects exist in a figure window, each axes has its own hold state. hold also creates an axes if one does not exist. hold on sets the NextPlot property of the current figure and axes to add. hold off sets the NextPlot property of the current axes to replace. hold toggles the NextPlot property between the add and replace states.

See Alsoaxis, cla, ishold, newplot The NextPlot property of axes and figure graphics objects. Basic Plots and Graphs for related func

zpk

Specify zero-pole-gain models or convert LTI model to zero-pole-gain form Syntaxsys = zpk(z,p,k)

sys = zpk(z,p,k,Ts)

sys = zpk(M)

sys = zpk(z,p,k,ltisys)

sys = zpk(z,p,k,'Property1',Value1,...,'PropertyN',ValueN)

sys = zpk(z,p,k,Ts,'Property1',Value1,...,'PropertyN',ValueN)

sys = zpk('s')

sys = zpk('z')

Page 10: tfdata

zsys = zpk(sys)

zsys = zpk(sys,'inv') % for state-space sys only

Description zpk

is used to create zero-pole-gain models (ZPK objects) or to convert TF or SS models to zero-pole-gain form. Creation of Zero-Pole-Gain Modelssys = zpk(z,p,k) creates a continuous-time zero-pole-gain model with zeros z, poles p, and gain(s) k. The output sys is a ZPK object storing the model data (see "LTI Objects" on page 2-3). In the SISO case, z and p are the vectors of real- or complex-valued zeros and poles, and k is the real- or complex-valued scalar gain. Set z or p to [] for systems without zeros or poles. These two vectors need not have equal length and the model need not be proper (that is, have an excess of poles). You can also use rational expressions to create a ZPK model. To do so, use either: s = zpk('s') to specify a ZPK model from a rational transfer function of the Laplace variable, s. z = zpk('z',Ts) to specify a ZPK model with sample time Ts from a rational transfer function of the discrete-time variable, z. Once you specify either of these variables, you can specify ZPK models directly as real- or complex-valued rational expressions in the variable s or z. To create a MIMO zero-pole-gain model, specify the zeros, poles, and gain of each SISO entry of this model. In this case: z and p are cell arrays of vectors with as many rows as outputs and as many columns as inputs, and k is a matrix with as many rows as outputs and as many columns as inputs. The vectors z{i,j} and p{i,j} specify the zeros and poles of the transfer function from input j to output i. k(i,j) specifies the (scalar) gain of the transfer function from input j to output i. See below for a MIMO example. sys = zpk(z,p,k,Ts) creates a discrete-time zero-pole-gain model with sample time Ts (in seconds). Set Ts = -1 or Ts = [] to leave the sample time unspecified. The input arguments z, p, k are as in the continuous-time case. sys = zpk(M) specifies a static gain M. sys = zpk(z,p,k,ltisys) creates a zero-pole-gain model with generic LTI properties inherited from the LTI model ltisys (including the sample time). See "Generic Properties" on page 2-26 for an overview of generic LTI properties. To create an array of ZPK models, use a for loop, or use multidimensional cell arrays for z and p, and a multidimensional array for k. Any of the previous syntaxes can be followed by property name/property value pairs. 'PropertyName',PropertyValue

Each pair specifies a particular LTI property of the model, for example, the input names or the input delay time. See set entry and the example below for details. Note that sys = zpk(z,p,k,'Property1',Value1,...,'PropertyN',ValueN)

is a shortcut for the following sequence of commands. sys = zpk(z,p,k)

set(sys,'Property1',Value1,...,'PropertyN',ValueN)

Zero-Pole-Gain Models as Rational Expressions in s or zYou can also use rational expressions to create a ZPK model. To do so, first type either: s = zpk('s') to specify a ZPK model using a rational function in the Laplace variable, s. z = zpk('z',Ts) to specify a ZPK model with sample time Ts using a rational function in the discrete-time variable, z. Once you specify either of these variables, you can specify ZPK models

Page 11: tfdata

directly as rational expressions in the variable s or z by entering your transfer function as a rational expression in either s or z. Conversion to Zero-Pole-Gain Formzsys = zpk(sys) converts an arbitrary LTI model sys to zero-pole-gain form. The output zsys is a ZPK object. By default, zpk uses zero to compute the zeros when converting from state-space to zero-pole-gain. Alternatively, zsys = zpk(sys,'inv')

uses inversion formulas for state-space models to compute the zeros. This algorithm is faster but less accurate for high-order models with low gain at . Variable SelectionAs for transfer functions, you can specify which variable to use in the display of zero-pole-gain models. Available choices include (default) and for continuous-time models, and (default), , or for discrete-time models. Reassign the 'Variable' property to override the defaults. Changing the variable affects only the display of zero-pole-gain models. ExampleExample 1Specify the following zero-pole-gain model. To do this, type z = {[] ; -0.5}

p = {0.3 ; [0.1+i 0.1-i]}

k = [1 ; 2]

H = zpk(z,p,k,-1) % unspecified sample time

Example 2Convert the transfer function h = tf([-10 20 0],[1 7 20 28 19 5])

Transfer function:

-10 s^2 + 20 s

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

s^5 + 7 s^4 + 20 s^3 + 28 s^2 + 19 s + 5

to zero-pole-gain form by typing zpk(h)

Zero/pole/gain:

-10 s (s-2)

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

(s+1)^3 (s^2 + 4s + 5)

Example 3Create a discrete-time ZPK model from a rational expression in the variable z, by typing z = zpk('z',0.1);

H = (z+.1)*(z+.2)/(z^2+.6*z+.09)

Zero/pole/gain:

(z+0.1) (z+0.2)

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

Page 12: tfdata

(z+0.3)^2

Sampling time: 0.1

Algorithmzpk uses the MATLAB function roots to convert transfer functions and the functions zero and pole to convert state-space models.