Upload
sudeep-balan
View
517
Download
2
Embed Size (px)
Citation preview
1
MATLAB commands for Modeling and analysis of LTI Systems
Creation of LTI models
1 tf Create a transfer function model.
2 ss Create a state‐space model.
3 zpk Create a zero/pole/gain model
Conversions
4 tf Conversion to transfer function.
5 ss Conversion to state space.
6 zpk Conversion to zero/pole/gain.
7 c2d. Continuous to discrete conversion
8 d2c Discrete to continuous conversion.
Time response
9 step Step response.
10 Impulse Impulse response.
11 lsim Response to arbitrary inputs.
12 Initial Response of state‐space system with given initial state.
Frequency response
13 bode Bode plot of the frequency response.
14 nyquist Nyquist plot.
15 nichols Nichols chart.
16 margin Gain and phase margins
System interconnections
17 parallel Generalized parallel connection.
2
18 series Generalized series connection.
19 feedback Feedback connection of two systems.
Control Design
20 rlocus Root locus plot.
21 rlocfind Interactive root locus gain determination
22 zgrid Generate z‐plane grid lines for a root locus or pole‐zero map.
23 acker SISO (single‐input‐single‐output) pole placement.
24 place MIMO (multiple‐input‐multiple‐output) pole placement.
3
1) Step Function in MATLAB
Step response of LTI models. Step calculates the unit step response of a linear system. Zero initial state is assumed in the state‐space case. When invoked without left‐hand arguments, this function plots the step response on the screen.
Step (sys) plots the step response of an arbitrary LTI model sys. This model can be continuous or discrete, and SISO or MIMO. The step response of multi‐input systems is the collection of step responses for each input channel. The duration of simulation is determined automatically based on the system poles and zeros.
Syntax: step(sys) step(sys,t)
To plot the step responses of several LTI models sys1,..., sysN on a single figure, use step (sys1,sys2,...,sysN) step (sys1,sys2,...,sysN,t)
Example 1:
To plot the step response of a transfer function
X S
F S S S
>>m =1 >>b=10 >>k=20 >>num = [1]; >>den= [m b k] >>t_function=tf (num, den) >>step (t_function) Example 2:
= . ..
+
. .
>>a= [‐0.5572 ‐0.7814; 0.781 0]; >>b=[1 ‐1;0 2];
4
>>c= [1.9691 6.4493]; >>sys=ss (a, b, c, 0);Creates state‐space model or converts model to state space. >>step (sys)
2) Bode Function in MATLAB
Bode frequency response of LTI models. Bode plot of frequency response, magnitude and phase. bode(sys,w) explicitly specifies the frequency range or frequency points to be used for the plot. To focus on a particular frequency interval [wmin, wmax],set w = {wmin, wmax}. To use particular frequency points, set w to the vector of desired frequencies.
Syntax :
bode(sys) bode(sys,w)
>>bode (t_function)
5
>>bode (t_function, {0.1, 10})
3) Nyquist Function in Matlab
Nyquist calculates the Nyquist frequency response of LTI systems. When invoked without lefthand arguments, nyquist produces a Nyquist plot on the screen. Nyquist plots are used to analyze system properties including gain margin, phase margin, and stability.
Syntax: nyquist(sys) nyquist(sys,w)
>>num = [1 2]; >>den = [1 ‐2 ‐3]; >>h = tf (num, den) >>nyquist (h)
6
4) Impulse Function in Matlab Impulse response of LTI system. Impulse calculates the unit impulse response of a linear system. The impulse response is the response to a Dirac input for continuous‐time systems and to a unit pulse at for discrete‐time systems. Zero initial state is assumed in the state‐space case.
Syntax: impulse(sys) impulse(sys,t) >>impulse (h)
5) rlocus Function in Matlab (Root Locus) Computes and Plots the root locus of the single‐input, single‐output LTI model system. The root locus plot is used to analyze the negative feedback loop. Root loci are used to study the effects of varying feedback gains on closed‐loop pole locations. In turn, these locations provide indirect information on the time and frequency responses.
Syntax :
rlocus(sys) rlocus(sys, k)
[r, k] = rlocus(sys) r = rlocus(sys, k)
2 5 12 3
>>h=tf ([2 5 1],[1 2 3]); >>rlocus (h)
7
6) rlocfind Function in Matlab
Select feedback gain from root locus plot.
Syntax:
[k, poles] = rlocfind (sys) [k, poles] = rlocfind (sys, p)
Rlocfind returns the feedback gain associated with a particular set of poles on the root locus. Rlocfind works with both continuous‐ and discrete‐time SISO systems.
2 5 12 3
>>h = tf ([2 5 1],[1 2 3]); >>rlocus(h) >>k = rlocfind (h)
7) lsim Function in Matlab (Linear Simulation)
Simulate time response of LTI models to arbitrary inputs. Lsim simulates the (time) response of continuous or discrete linear systems to arbitrary inputs. When invoked without lefthand arguments, lsim plots the response on the screen.
Syntax: lsim(sys,u,t) lsim(sys,u,t,x0)
Simulate and plot the response of the system
to a square wave with period of four seconds. Sample every 0.1
second during 10 seconds:
>> [u ,t] = gensig('square',4,10,0.1) >> H = [tf([2 5 1],[1 2 3]) ; tf([1 ‐1],[1 1 5])] >> lsim(H,u,t)
8
8) Polyval Function in Matlab (Polynomial Evaulation) y = polyval(p,x) returns the value of a polynomial of degree n evaluated at x. The input
argument p is a vector of length n+1 whose elements are the coefficients in descending
powers of the polynomial to be evaluated.
+…………+
x can be a matrix or a vector. In either case, polyval evaluates p at each element of x.
Syntax:
y = polyval (p,x)
The Polynomial 3 2 1 is evaluated at x=5, 7 and 9
>>p = [3 2 1];
>>polyval (p,[5 7 9])
ans = 86 162 262
9
9)Logspace Function in Matlab (Logarithmically spaced vector)
The logspace function generates logarithmically spaced vectors. Especially useful for creating frequency vectors, it is a logarithmic equivalent oflinspace and the ":" or colon operator.
Syntax:
y = logspace(a,b) y = logspace(a,b,n) y = logspace(a,pi) y = logspace(a,b) generates a row vector y of 50 logarithmically spaced points between decades 10 and 10 . y = logspace(a,b,n) generates n points between decades 10 and 10 . y = logspace(a,pi) generates the points between 10 and pi, which is useful for digital signal processing where frequencies over this interval go around the unit circle.
>>x=logspace (1, 4, 4)
x = 10 100 1000 10000
>> x = logspace(2,pi)
x = Columns 1 through 15
100.0000 93.1815 86.8279 80.9075 75.3908 70.2503 65.4602 60.9968 56.8377 52.9622 49.3510 45.9860 42.8504 39.9287 37.2061
Columns 16 through 30
34.6692 32.3053 30.1025 28.0500 26.1374 24.3552 22.6945 21.1471 19.7052 18.3616 17.1096 15.9430 14.8559 13.8429 12.8991
Columns 31 through 45
12.0195 11.2000 10.4363 9.7247 9.0616 8.4438 7.8680 7.3315 6.8316 6.3658 5.9318 5.5273 5.1504 4.7992 4.4720
Columns 46 through 50
4.1671 3.8829 3.6182 3.3715 3.1416
10
10) Semilogx Function in Matlab (Semilogarithmic plot)
Semilogx and semilogy plot data as logarithmic scales for the x‐ and y‐axis, respectively. Logarithmic semilogx(Y) creates a plot using a base 10 logarithmic scale for the x‐axis and a linear scale for the y‐axis. It plots the columns of Y versus their index if Y contains real numbers. semilogx(Y) is equivalent to semilogx(real(Y), imag(Y)) if Y contains complex numbers. Semilogx ignores the imaginary component in all other uses of this function.
Syntax:
semilogx(Y) semilogx(X1,Y1,...) semilogx(X1,Y1,LineSpec,...) semilogx(...,'PropertyName',PropertyValue,...) h = semilogx(...)
Create a simple semilogy plot.
>>x = 0:.1:10; >>semilogy(x, 10.^x)
11) Series Function in Matlab (Series connection of two LTI models)
Series connects two LTI models in series. This function accepts any type of LTI model. The two systems must be either both continuous or both discrete with identical sample time. Static gains are neutral and can be specified as regular matrices.
Syntax:
sys = series(sys1,sys2) sys = series(sys1,sys2,outputs1,inputs2)
11
sys = series(sys1,sys2)
forms the basic series connection shown below
sys = series(sys1,sys2,outputs1,inputs2)
12) Feedback Function in Matlab
Feedback connection of two LTI models. sys = feedback(sys1,sys2)returns an LTI model sys for the negative feedback interconnection.
Syntax:
sys = feedback(sys1,sys2) Examples:
12
2 5 1
2 3
5 2
10
>>G = tf([2 5 1],[1 2 3])
>>H = zpk (‐2,‐10,5)
>>Cloop = feedback(G,H)
Zero/pole/gain: 0.18182 (s+10) (s+2.281) (s+0.2192) ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ (s+3.419) (s^2 + 1.763s + 1.064) 13) Cloop Function in Matlab (Closed loop Connection)
22 3
>> num1= [ 1 2];den1=[1 2 3 ]; >> [num ,den]=cloop (num1,den1,‐1) >> G=tf(num ,den)
R(s) Y(s)
13
14) Meshz Function in Matlab mesh, meshc, and meshz create wireframe parametric surfaces specified by X, Y, and Z, with color specified by C. Generate a "waterfall" plot for the peaks function using meshz. Syntax:
mesh(X,Y,Z) mesh(Z) mesh(...,C)
>>[X,Y] = meshgrid(‐3:.125:3);
>>Z = peaks(X,Y);
>>meshz(X,Y,Z)
15) Meshgrid Function in Matlab Generate X and Y arrays for 3‐D plots. [X,Y] = meshgrid(x,y) transforms the domain specified by vectors x and y into arrays X and Y, which can be used to evaluate functions of two variables and three‐dimensional mesh/surface plots. The rows of the output array X are copies of the vector x; columns of the output array Y are copies of the vector y. Syntax
[X,Y]=meshgrid(x,y) [X,Y]=meshgrid(x) [X,Y,Z] = meshgrid(x,y,z)
[X,Y] = meshgrid(1:3,10:14)
X =
1 2 3
1 2 3
1 2 3
1 2 3
1 2 3
Y =
10 10 10
11 11 11
14
12 12 12
13 13 13
14 14 14
[X,Y] = meshgrid(‐2:.2:2, ‐2:.2:2);
Z = X .* exp(‐X.^2 ‐ Y.^2);
surf(X,Y,Z)
16) Printsys Function in Matlab PRINTSYS Print system in pretty format. PRINTSYS is used to print state space systems with labels to the right and above the system matrices or to print transfer functions as a ratio of two polynomials. PRINTSYS (A,B,C,D) prints the system with numerical labels. PRINTSYS(NUM,DEN,'s') or PRINTSYS(NUM,DEN,'z') prints the transfer function as a ratio of two polynomials in the transform variable 's' or 'z'. >> printsys(num,den)
num/den = s + 2 ‐‐‐‐‐‐‐‐‐‐‐‐‐ s^2 + 3 s + 5
17) Nichols Function in Matlab Nichols frequency response of LTI models. nichols creates a Nichols chart of the frequency response of a dynamic system, displays the magnitude (in dB) plotted against the phase (in degrees) of the system response. Nichols charts are useful to analyze open‐ and closed‐loop properties of SISO systems, but offer little insight into MIMO control loops. Use ngridchart. Syntax:
nichols nichols(sys) nichols(sys,w) nichols(sys1,sys2,...,sysN,w)
Nichols Chart of Dynamic System
4 48 18 250 60030 282 525 60
>>num = [‐4 48 ‐18 250 600]; >> den = [1 30 282 525 60];
15
>>H = tf(num,den) Transfer function: ‐4 s^4 + 48 s^3 ‐ 18 s^2 + 250 s + 600 ‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐ s^4 + 30 s^3 + 282 s^2 + 525 s + 60 >> nichols(H); ngrid 18) Ss2tf Function in Matlab (State Space to Transfer Function)
Convert state‐space filter parameters to transfer function form. ss2tf converts a state‐space representation of a given system to an equivalent transfer function representation.
Syntax:
[b,a]=ss2tf(A,B,C,D,iu) >>num= [1 0 1]; >> den=[2 1 0]; >> [A,B,C,D]=tf2ss(num,den) A = ‐0.5000 0 1.0000 0 B = 1 0 C = ‐0.2500 0.5000 D = 0.5000 >> [n,d]=ss2tf(A,B,C,D) n = 0.5000 ‐0.0000 0.5000 d = 1.0000 0.5000 0
16
19) acker Function in Matlab Pole placement design for single‐input systems. Compute the K matrix to place the poles of A‐BK Syntax:
k = acker(A,b,p)
Given the single‐input system
and a vector p of desired closed‐loop pole locations, acker (A,b,p) uses Ackermann's formula to calculate a gain vector k such that the state feedback u = −kx places the closed‐loop poles at the locations p. >> A=[0 1 0; 1960 0 ‐15.66; 0 20.87 ‐16.66]; >> B=[0;0;1.6667]; >> C=[1 0 0]; >> D=0; >>K = acker(A,B,[‐20 ‐20 ‐20]) desired closed‐loop eigenvalues : λ1 = λ2 = λ3 = − 20 K = 1.0e+003 * ‐4.8152 ‐0.1086 0.0260 The results can be verified by computing the closed‐loop eigenvalues. >> eig(A‐B*K)
‐20.0002 + 0.0003i ‐20.0002 ‐ 0.0003i ‐19.9997
20) ode45 Function in Matlab (Ordinary Differential Equations)
MATLAB's standard solver for ordinary differential equations (ODEs) is the function ode45. Solve initial value problems for ordinary differential equations.
Syntax:
[T,Y] = solver(odefun,tspan,y0) [T,Y] = solver(odefun,tspan,y0,options) [T,Y,TE,YE,IE] = solver(odefun,tspan,y0,options) sol = solver(odefun,[t0 tf],y0...)
17
Example : Use ode23 and ode45 to solve the initial value problem for a first order differential equation:
2, 0 1, 0,5
First create a MatLab function and name it fun1.m.
function f=fun1(t,y) f=‐t*y/sqrt(2‐y^2);
Now use functions ode23 and ode45 to solve the initial value problem numerically
>> [tv1 f1]=ode23('fun1',[0 5],1); >> [tv2 f2]=ode45('fun1',[0 5],1); >> plot(tv1,f1,'‐.',tv2,f2,'‐‐') >> title('y''=‐ty/sqrt(2‐y^2), y(0)=1, t in [0, 5]') >> grid >> axis([0 5 0 1])
The numerical solutions f1 and f2 respectively generated by ode23 and ode45 are almost the same for this example.