Professional Documents
Culture Documents
u(t) U(s)
H ( s) =
Y (S ) U ( s)
num den
2
y(t) Y(s)
2 . Recall that the step response is s + 2s + 4 defined as the output y(t) of the system applying unity step function input u(t)=1(t) assuming zero initial conditions. The transfer function can be defined in MATLAB by its numerator and denominator in a polynomial form: num = 2 , den = s 2 + 2 s + 4 . The polynomials are defined by their coefficients put in a vector by descending order of s : num=2 Step response 0.7 den=[1 2 4] The step response of the system can be displayed directly by the 0.6 MATLAB step command: 0.5 step(num,den); Note that equivalently, the compact form of 0.4 step(2,[1 2 4]); 0.3 is also applicable. Observe that the time scale is automatically selected 0.2 by MATLAB. Expanding the above command by a left-hand side argument it is 0.1 possible to store the values of the step response function in an array: 0 [y,x,t]=step(num,den) % or simpler 0 1 2 3 4 5 6 y=step(num,den) Note that no plot is generated in this case. If a semicolon (;) terminates the line the numerical values are not displayed either. The left-hand side variables are the output variables, y is the output of the step response, t gives the time points where it has been calculated, while x provides two so-called inner variables. The values stored in a variable can be displayed any time by typing the name of the variable: y The result is a column vector whose elements are the calculated samples of the step response function. The sampling time applied by MATLAB can be calculated from the time interval 0 t 6 and the size of the vector: n=length(y) n = 109 T=6/n T = 0.055 The calculated sampling time: T=6/109=0.055 sec. The help command shows further possible forms of the step command: help step It is seen then that there are other ways to use the step command. E.g. if the time interval 0 t 10 and the sampling time T = 0.1 are explicitly selected by t=0:0.1:10 the following form is applicable: y=step(num,den,t) The output vector can now be displayed with the plot command: plot(t,y); or adding the grid option to support the easy reading of the plot plot(t,y),grid; As far as the visualization is concerned, the plot command uses linear interpolation between the calculated samples. To avoid this interpolation the plot(t,y,'.');
Introduction to Matlab Control System Toolbox command displays only the calculated samples. The maximum of the step response (more exactly the largest calculated sample) can be determined by ym=max(y) ym = 0.5815 The steady state value of the step response is obtained as ys=dcgain(num,den) ys = 0.5 and the percentage overshoot of the output is yovrsht=(ym-ys)/ys*100 yovrsht = 16.2971
This partial fraction expansion conversion can be done by the residue command. polynomial form: num=[3 13 16]; den=poly([-3 -3 -2]); The partial fraction expansion is obtained by [r,p,k]=residue(num,den) r = 1.0000 -4.0000 2.0000 p = -3.0000 -3.0000 -2.0000 k = []
Define
the
function
in
The partial fraction form in the Laplace domain r (1) r (2) r (3) 1 4 2 Y (s) = + + +k = + s p (1) ( s p (2)) 2 s p (3) s + 3 ( s + 3) 2 s + 2 and in time domain: y (t ) = e 3t 4te3t + 2e2t , t 0 Notice the form of the double poles. The time function can be calculated from the analytical expression: t=0:0.05:6; y=r(1)*exp(p(1)*t)+r(2)*t.*exp(p(2)*t)+r(3)*exp(p(3)*t); (The .* means element-by-element type multiplication). The analytical expression can be verified by numerical simulation. Then the two curves can be plotted in the same diagram. yi=impulse(num,den,t); plot(t,[y,yi]),grid;
& x = Ax + Bu y = Cx + Du
Using the MATLAB commands tf, zpk and ss, the transfer function H(s) can be defined as an LTI data-structure: num=2 den=[1, 3, 2] H=tf(num,den) Transfer function: 2 ------------s^2 + 3 s + 2 or directly Htf=tf(2,[1, 3, 2]) The other models can be defined in a similar way: Hzpk=zpk([],[-1, -2],2) Zero/pole/gain: 2 ----------(s+1)(s+2) A=[-3, -1; 2, 0]; B=[1; 0]; C=[0, 1]; D=0; Hss=ss(A,B,C,D); Conversions between a pair of the models are available as follows: Hzpk1=zpk(Htf) Hss1=ss(Htf) Htf1=tf(Hss) The models contain parameters. These parameters together with the data-structure can be listed by get(Htf) get(Hzpk) get(Hss) The parameters (properties) in an LTI structure can be accessed. The 'v' flag means that the result is in vector format: [num1,den1]=tfdata(Htf,'v') num1 = 0 0 2 den1 = 1 3 2 [z,p,k]=zpkdata(Hzpk,'v') or they can be accessed directly num2=Htf.num{1} num2 = 0 0 2 The term {1} has to be used since the transfer function can represent MIMO (multiple input-multiple output) systems, in general. Also, {1} identifies cell-array type. The cell-array is a matrix with matrices of variable size. For example ca={1, [1,2],[1,2,3]} ca = [1] [1x2 double] [1x3 double] ca{2}
ans = 1 2 The other models can be accessed in a similar way: Hzpk.k=2; Hzpk.z=[]; Hzpk.p=[-1, -2]; Hzpk k: 2 z: [] p: [-1 -2] Hss.a ans = -3 -1 2 0 . Symbolic data input can also be used if the s variable is defined s=tf('s') H=1/((s+1)*(s+2)) You can apply arithmetic operators to LTI models. The defined operators are: +, - , / , \ , ' , inv, ^ . For example a resulting transfer function Hcl can be given by the following symbolic calculation: Hcl=H/(1+H) There is a hierarchy of the LTI structures: tf -> zpk -> ss. If in an operation different structures are used the result is stored in the highest hierarchy structure. For example the result of Htf*Hzpk is stored in zpk form.
plot(x1,x2) Output response to an arbitrary input: The output can also be calculated for any input signal. Calculate the system response, if the input is u(t)= 2*sin(3*t). usin=2*sin(3*t); ysin=lsim(H,usin,t); Plot both the input (red) and output (blue): plot(t,usin,'r',t,ysin,'b'), grid;
LTI Viewer:
A linear system can be analyzed in details by the LTI Viewer. The LTI Viewer is a graphical user interface for analyzing the system response in time and frequency domain. The systems and the curves can be manipulated from menus or by the right mouse button:
To: Y(1)
Simulink:
SIMULINK is a graphical software package supporting block-oriented system analysis. SIMULINK has two phases, model definition and model analysis. First a model has to be defined than it can be analyzed by running a simulation. SIMULINK represents dynamic systems with block diagrams. Defining a system is much like drawing a block diagram. Instead of drawing the individual blocks, blocks are copied from libraries of blocks. The standard block library is organized into several subsystems, grouping blocks according to their behavior. Blocks can be copied from these or any other libraries or models into your model. SIMULINK block library can be opened from the MATLAB command window by entering command simulink . This command displays a new window containing icons for the subsystem blocks. Constructing your model select New from the File menu of SIMULINK to open a new empty window in which you can build your model. Open one or more libraries and drag some blocks into your active window. To build your model you can drag the appropriate blocks by the left mouse button from their libraries to your file to the required position where you release the button. To connect two blocks use the left mouse button to click on either the output or input port of one block, drag to the other block's input or output port to draw a connecting line, and then release the button. By clicking on the block with the right button you can duplicate it. The blocks can be increased, decreased, rotated. Open the blocks by double clicking to change some of their internal parameters. Save the system by selecting Save from the File menu. Run a simulation by selecting Start from the Simulation menu. Simulation parameters can also be changed. You can monitor the behavior of your system with a Scope or you can use the To Workspace block to send data to the MATLAB workspace and perform MATLAB functions (e.g. plot) on the results. Parameters of the blocks can be referred also by variables defined in MATLAB. Simulation of SIMULINK models involves the numerical integration of sets of ordinary differential equations. SIMULINK provides a number of integration algorithms for the simulation of such equations. The appropriate choice of method and the careful selection of simulation parameters are important considerations for obtaining accurate results. To get yourself familiarized with the flavour of the the options offered by SIMULINK consider the following example: Create a new file and copy various blocks. The block parameters should then be changed to the required value. Change the Simulation>Parameters>Stop time parameter to 50 from the menu. SIMULINK uses the variables defined in the MATLAB workspace. H(s): Control System Toolbox >LTI system : H Difference: Simulink>Math>Sum: +Dead time, delay: Simulink>Continuous>Transport Delay: 1 Gain: Simulink>Math>Gain: 1 Step input: Simulink>Sources>Step Scope: Simulink>Sinks>Scope Clock: Simulink>Sources>ClockOutput, time: Simulink>Sinks>To Workspace: y,t
t Clock time 1.5 Step Input Gain H LTI SystemPs Transport Delay Scope1
y output
The result can be analyzed directly by the Scope block or it can be send back to the MATLAB workspace by the To Workspace output block . The results there can be further processed and displayed graphically. Change the Gain parameter between 0.5 and 2. Determine the parameter value for which the system produces constant oscillation.