This action might not be possible to undo. Are you sure you want to continue?

1. OBJECTIVES At the end of the experiment, students should be able to 1) Use MATLAB‟s Control System Toolbox to solve control systems problems 2) Analyze control systems problems 2. INTRODUCTION Before you begin the next sections, it would be a good idea to run the MATLAB Control System Toolbox demo. This is done by typing “demo(‟toolbox‟,‟control‟)” at the MATLAB prompt. Aside from the basic MATLAB plotting commands, you should become familiar with the following commands: tf (transfer function)– This command is used to enter transfer functions. For example, to s 2 enter the transfer function H ( s) you would type “H=tf([1 2],[1 0 5])”. The first s2 5 parameter is a row vector of the numerator coefficients. Similarly, the second parameter is a row vector of the denominator coefficients. Conv (convulation) – This command is used to convolve two polynomials. It is particularly useful for determining the expanded coefficients for factored polynomials. For example, s 2 this command can be used to enter the transfer function H ( s) by typing ( s 1)(2 3) “H=tf([1 2],conv([1 1],[1 -3]))” series or * – This command is used to combine two transfer functions that are in series. For example, if H(s) and G(s) are in series, they could be combined with the command “T=G*H” or “T=series(G,H)”. feedback – This command is used to combine two transfer functions that are in feedback. For example, if G(s) is in the forward path and H(s) is in the feedback path, they could be combined with the command “T=feedback(G,H)”. step – This command is used to plot the step response of a system. For example, “step(T)” would plot the step response of the system T (s). bode – This command is used to plot the frequency repsonse. For example, “bode(T)” would plot the frequency response of the system T (s). rlocus – This command is used to plot the root locus. For example, “bode(G*H)” would plot the frequency response of the system G(s)H(s). Keep in mind that this command is used on the loop gain of the system as opposed to the closed-loop transfer function. For example, consider the standard negative feedback system with forward path G and feedback path H. The loop gain G(s) would be G(s)H(s) whereas the closed-loop transfer function would be 1 G(s) H (s)

Page 1 of 15

3. PROCEDURES Open the MATLAB‟s icon from the Desktop. Select File > New > M-File. Write down the codes from Exercise#1. Exercise #1 Bit strings will be used to identify parts of this tutorial on the computer output. Bit strings are represented by the text enclosed in apostrophes, such as 'ab'. Comments begin with % and are ignored by MATLAB. Numbers are entered without any other characters. Arithmetic can be performed using the proper arithmetic operator. Numbers can be assigned using a left-hand argument and an equal sign. 'Ex1' 'How are you?' -3.96 -4+7i -5-6j (-4+7i)+(-5-6i) (-4+7j)*(-5-6j) M=5 N=6 P=M+N % Display label. % Display string. % Display scalar number -3.96. % Display complex number -4+7i. % Display complex number -5-6i. % Add two complex numbers and display sum. % Multiply two complex numbers and display product. % Assign 5 to M and display. % Assign 6 to N and display. % Assign M+N to P and display.

Select File > Save As. Save the file as Lab1Ex1. Select Debug > Run to run the program. Repeat above steps for the following exercises and save files appropriately. Exercise #2 Polynomials in s can be represented as row vectors containing the coefficients. Thus P1 = s3 + 7s2 -3s + 23 can be represented by the vector shown below with elements separated by a space or comma. Bit strings can be used to identify each section of this tutorial. 'Ex2' P1=[1 7 -3 23] % Display label. % Store polynomial s^3 + 7s^2 -3s + 23 as P1 and display.

Exercise #3 Running the previous statements causes MATLAB to display the results. Ending the command with a semicolon suppresses the display. Typing an expression without a left-hand assignment and without a semicolon causes the expression to be evaluated and the result displayed. Enter P2 in the MATLAB Command Window after execution. 'Ex3' P2=[3 5 7 8]; 3*5 % Display label. % Assign 3s^3 + 5s^2 +7s + 8 to P2 without displaying. % Evaluate 3*5 and display result.

Page 2 of 15

Exercise #4 An F(s) in factored form can be represented in polynomial form. Thus P3 = (s+2)(s+5)(s+6) can be transformed into a polynomial using poly(V), where V is a row vector containing the roots of the polynomial and poly(V) forms the coefficients of the polynomial. 'Ex4' P3=poly([-2 -5 -6]) % Display label. % Store polynomial (s+2)(s+5)(s+6) as P3 and display the coefficients

Exercise #5 We can find roots of polynomials using the roots(V) command. The roots are returned as a column vector. For example, find the roots of 5s4+7s3+9s2-3s+2 = 0. 'Ex5' P4=[5 7 9 -3 2] rootsP4=roots(P4) % Display label. % Form 5s^4+7s^3+9s^2-3s+2 and display. % Find roots of 5s^4+7s^3+9s^2-3s+2, assign to roots P4, and display.

Exercise #6 Polynomials can be multiplied together using the conv(a,b) command (standing for convolve). Thus, P5=(s3+7s2+10s+9)(s4-3s3+6s2+2s+1) is generated as follows: 'Ex 6' P5=conv([1 7 10 9],[1 -3 6 2 1]) P5, % Display label. % Form (s^3+7s^2+10s+9)(s^4-3s^3+6s^2+2s+1), assign to % and display.

Exercise #7 The partial-fraction expansion for F(s) = b(s)/a(s) can be found using the [K,p,k] = residue(b,a) command (K = residue; p = roots of denominator; k = direct quotient, which is found by dividing polynomials prior to performing a partial-fraction expansion). 7 s 2 9s 12 We expand F ( s) as an example. Using the results from MATLAB yields: s( s 7)(s 2 10s 100) (0.2554 0.3382i) (0.2554 0.3382i) 0.5280 0.0171 F ( s) (s 5.0000 8.6603i) (s 5.0000 8.6603i) (s 7) s

'Ex 7' numf=[7 9 12]; denf=conv(poly([0 -7]),[1 10 100]); [K,p,k]=residue(numf,denf)

% Display label. % Define numerator of F(s) as „numf‟. % Define denominator of F(s) as „denf‟. % Find residues and assign to K; find roots of denominator % and assign to p; find constant and assign to k.

**Exercise #8 Let us do Example 2.3 in the book using MATLAB. Given Y ( s) 'Example 2.3' numy=32; deny=poly([0 -4 -8]);
**

s( s

2

32 12s 32)

32 s( s 4)(s 8)

% Display label. % Define numerator as „numy‟. % Define denominator as „deny‟ in polynomials.

Page 3 of 15

[r,p,k] = residue(numy,deny)

% Calculate residues and assign to r, find roots of denominator % and assign to p; find constant and assign to k

Exercise #9 Vector Method, Polynomial Form: A transfer function can be expressed as a numerator polynomial divided by a denominator polynomial, i.e. F(s) = N(s)/D(s). The numerator, N(s), is represented by a row vector, numf, that contains the coefficients of N(s). Similarly, the denominator, D(s), is represented by a row vector, denf, that contains the coefficients of D(s). We form F(s) with the command, F = tf(numf,denf). F is called a linear time-invariant (LTI) object. This object, or transfer function, can be used as an entity in other operations, such as addition or multiplication. We demonstrate with F(s) = 150(s2+2s+7)/[s(s2+5s+4)]. Notice after executing the tf command, MATLAB prints the transfer function. 'Ex9:Vector Method, Polynomial Form' numf=150*[1 2 7] denf=[1 5 4 0] 'F(s)' F=tf(numf,denf) clear Vector Method, Factored Form: We also can create LTI transfer functions if the numerator and denominator are expressed in factored form. We do this by using row vectors containing the roots of the numerator and denominator. Thus G(s) = K*N(s)/D(s) can be expressed as an LTI object using the command, G = zpk(numg,deng,K), where numg is a row vector containing the roots of N(s) and deng is a row vector containing the roots of D(s). The expression zpk stands for zeros (roots of the numerator), poles (roots of the denominator), and gain, K. We demonstrate with G(s) = 20(s+2)(s+4)/[(s+7)(s+8)(s+9)]. Notice after executing the zpk command, MATLAB prints the transfer function. 'Vector Method, Factored Form' numg=[-2 -4] deng=[-7 -8 -9] K=20 'G(s)' G=zpk(numg,deng,K) clear % Display label. % Store (s+2)(s+4) in numg and display. % Store (s+7)(s+8)(s+9) in deng and display. % Define K. % Display label. % Form G(s) and display. % Clear previous variables from workspace. % Display label. % Store 150(s^2+2s+7) in numf and display. % Store s(s+1)(s+4) in denf and display. % Display label. % Form F(s) and display.

Rational Expression in s Method, Polynomial Form: This method allows you to type the transfer function as you normally would write it. The statement s = tf('s') must precede the transfer function if you wish to create an LTI transfer function in polynomial form equivalent to using G=tf(numg,deng). 'Rational Expression Method, Polynomial Form' s=tf('s') % Display label. % Define 's' as an LTI object in polynomial % form.

Page 4 of 15

F=150*(s^2+2*s+7)/[s*(s^2+5*s+4)] G=20*(s+2)*(s+4)/[(s+7)*(s+8)*(s+9)] clear Rational Expression in s Method, Factored Form:

% Form F(s) as an LTI transfer function in % polynomial form. % Form G(s) as an LTI transfer function in % polynomial form. % Clear previous variables from workspace.

This method allows you to type the transfer function as you normally would write it. The statement s = zpk('s') must precede the transfer function if you wish to create an LTI transfer function in factored form equivalent to using G = zpk(numg,deng,K). For both rational expression methods the transfer function can be typed in any form regardless of whether s = tf('s') or s = zpk('s') is used. The difference is in the created LTI transfer function. We use the same examples above to demonstrate the rational expression in s methods. 'Rational Expression Method, Factored Form' s=zpk('s') F=150*(s^2+2*s+7)/[s*(s^2+5*s+4)] G=20*(s+2)*(s+4)/[(s+7)*(s+8)*(s+9)] Exercise #10 Transfer function numerator and denominator vectors can be converted between polynomial form containing the coefficients and factored form containing the roots. The MATLAB function, tf2zp(numtf,dentf), converts the numerator and denominator from coefficients to roots. The results are in the form of column vectors. We demonstrate this with F(s) = (10s2+40s+60)/(s3+4s2+5s+7). The MATLAB function, zp2tf(numzp,denzp,K), converts the numerator and denominator from roots to coefficients. We demonstrate the conversion from roots to coefficients with G(s) = 10(s+2)(s+4)/[s(s+3)(s+5)]. 'Ex10:Coefficients for F(s)' numftf=[10 40 60] denftf=[1 4 5 7] 'Roots for F(s)' [numfzp,denfzp]=tf2zp(numftf,denftf) % Display label. % Display label. % Define 's' as an LTI object in factored form. % Form F(s) as an LTI transfer function in factored form. % Form G(s) as an LTI transfer function in factored % form.

10s 2 40s 60 % Form numerator of F ( s) s 3 4 s 2 5s 7 10s 2 40s 60 % Form denominator of F ( s) s 3 4 s 2 5s 7 % Display label. % Convert F(s) to factored form.

'Roots for G(s)' % Display label. numgzp=[-2 -4] % Form numerator of G(s) = 10(s+2)(s+4)/[s(s+3)(s+5)]. K=10 % Form the value of gain dengzp=[0 -3 -5] % Form denominator of the G(s) 'Coefficients for G(s)' % Display label. [numgtf,dengtf]=zp2tf(numgzp',dengzp',K) % Convert G(s) to polynomial form. Exercise #11 LTI models can also be converted between polynomial and factored forms. MATLAB commands tf and zpk are also used for the conversion between LTI models. If a transfer function, Fzpk(s), is

Page 5 of 15

expressed as factors in the numerator and denominator, then tf(Fzpk) converts Fzpk(s) to a transfer function expressed as coefficients in the numerator and denominator. Similarly, if a transfer function, Ftf(s) is expressed as coefficients in the numerator and denominator, then zpk(Ftf) converts Ftf(s) to a transfer function expressed as factors in the numerator and denominator. The following example demonstrates the concepts. 'Ex11' 'Fzpk1(s)' Fzpk1=zpk([-2 -4],[0 -3 -5],10) 'Ftf1' Ftf1=tf(Fzpk1) 'Ftf2' Ftf2=tf([10 40 60],[1 4 5 7]) 'Fzpk2' Fzpk2=zpk(Ftf2) % Display label. % Display label. % Form Fzpk1(s)=10(s+2)(s+4)/[s(s+3)(s+5)]. % Display label. % Convert Fzpk1(s) to coefficients form. % Display label. % Form Ftf2(s)= 10s^2+40s+60)/(s^3+4s^2+5s+7). % Display label. % Convert Ftf2(s) to factored form.

4. DISCUSSION (CO2) Consider the following system:

C ( s) by using MATLAB. Show the MATLAB commands required to calculate T (s). R( s ) Make use of the commands zpk and feedback.

Find T ( s)

Hint:

T ( s)

C ( s) R( s )

G( s) 1 G( s) H ( s)

feedback(G(s), H (s))

5. CONCLUSION List out what you have learned from this experiment.

Page 6 of 15

LABORATORY TASK 1 PART 2: INTRODUCTION TO SIMULINK

1. OBJECTIVES At the end of the experiments, students should be able to: 1) Build simulation models using Simulink Version 6.0. 2) Model, simulate and analyze dynamic systems. 3) Obtain a system step response from Simulink‟s simulation. 2. INTRODUCTION Simulink is a software package that integrated with MATLAB that enables us to model, simulate and analyze systems whose outputs change over time (Dynamic Systems). Simulink can be used to explore the behavior of a wide range of real-world dynamic systems, including electrical circuits, shock absorbers, braking systems, and many other electrical, mechanical, and thermodynamic systems. 3. THEORY Simulating a dynamic system is a two-step process with Simulink: 1) First, a graphical model of the dynamic system is created by using the Simulink‟s model editor. The model depicts the time-dependent mathematical relationships among the system's inputs, states, and outputs.

2) Then, Simulink is used to simulate the behavior of the system over a specified time span. Simulink uses information that has been entered into the model to perform the simulation. Simulink provides a library browser that allows you to select blocks from libraries of standard blocks and a graphical editor that allows you to model virtually any real-world dynamic system by selecting and interconnecting the appropriate Simulink blocks. 4. TOOL / EQUIPMENT I) PC 2) MATLAB Simulink Version 4.0

5. PROCEDURES Exercise Build a simple model that integrates a sine wave and displays the result in Simulink.

Page 7 of 15

Please follow the steps below to build a model shown in Figure 1 above. STEP 1 Type Simulink in the MATLAB command window. Simulink Library Browser will appear as shown in Figure 2. STEP2 Create a new model by selecting New Model button on the Library Browser's toolbar.

Simulink opens a new model window as Figure 3 below.

Simulink opens a new model window as in Figure 3 below.

STEP 3 To create the model, you will need to copy blocks into the model window from the following Simulink block libraries: Sources library (the Sine Wave block)

Page 8 of 15

Sinks library (the Scope block) Continuous library (the Integrator block) Signals & Systems library (the Mux block) You can copy a Sine Wave block from the Sources library, using the Library Browser. Method1 - To copy the Sine Wave block from the Library Browser, first expand the Library Browser tree to display the blocks in the Sources library. Do this by clicking on the Sources node to display the Sources library blocks. Finally click on the Sine Wave node to select the Sine Wave block. Figure 4 is how the Library Browser should look after you have done this.

STEP 5 Now click and drag the Sine Wave block from the browser and drop it in the model window. Simulink creates a copy of the Sine Wave block at the point where you dropped the node icon as in Figure 5.

Method 2 - To copy the Sine Wave block from the Sources library window, open the Sources window by double-clicking on the Sources icon in the Simulink library window. (On Windows, you can open the Simulink library window by right-clicking the Simulink node in the Library Browser and then clicking the resulting Open Library button.)

Page 9 of 15

Simulink displays the Sources library window as in Figure 6.

STEP 6 Now click and drag the Sine Wave block from the Sources window to your model window as in Figure 5. (Note: If you need to copy any existing blocks from the model window, just press right click on you mouse button, hold the click and drag it to the required position or location). STEP 7 Copy the rest of the blocks in a similar manner from their respective libraries into the model window. You can move a block from one place in the model window to another by dragging the block. You can move a block a short distance by selecting the block, then pressing the arrow keys. With all the blocks copied into the model window, the model should looks something like Figure 7 below.

If you examine the block icons, you see an angle bracket on the right of the Sine Wave block and two on the left of the Mux block. The > symbol pointing out of a block is an output port; if the symbol points to a block, it is an input port. A signal travels out of an output port and into an input port of another block through a connecting line. When the blocks are connected, the port symbols disappear.

Page 10 of 15

STEP 8 Connect the Sine Wave block to the top input port of the Mux block. Position the pointer over the output port on the right side of the Sine Wave block. Notice that the cursor shape changes to crosshairs as shown in Figure 8 below.

Hold down the left mouse button and move the cursor to the top input port of the Mux block. Notice that the line is dashed while the mouse button is pressed and the cursor shape changes to double-lined crosshairs as it approaches the Mux block as shown in Figure 9.

Now release the mouse button. The blocks are connected as shown in Figure 10. You can also connect the line to the block by releasing the mouse button while the pointer is inside the icon. If you do, the line is connected to the input port closest to the cursor's position.

STEP 9 If you look again at the model at the beginning of this section (see Figure 1), you will notice that, most of the lines connect output ports of blocks to input ports of other blocks. Also, a line could connect to another line. This line, called a branch line, connects the line Wave output to the Integrator block, and carries the same signal that passes from the Sine Wave Lock to the Mux block. Drawing a branch line is slightly different from drawing the line you just drew. To create a connection to an existing line, follow the following steps: i) First, position the pointer on the line between the Sine Wave and the Mux block as shown in Figure 11.

Page 11 of 15

ii)

Press and hold down the Ctrl key (or click the right mouse button). Press the mouse button, then drag the pointer to the Integrator block's input port or over the Integrator block itself as shown in Figure 12.

iii)

Release the mouse button. Simulink draws a line to the Integrator block's input port as shown in Figure 13.

iv)

Complete the other lines so that your model looks as in Figure 14.

STEP 10 Now, open the Scope block by double-click the block to view the simulation output. Keeping the Scope window opens, set up Simulink to run the simulation for 10 seconds. First, set the simulation parameters by choosing Simulation Parameters from the Simulation menu. On the dialog box that appears as shown in Figure 15 below, set the Stop time to 10.0.

Page 12 of 15

STEP 11 Close the Simulation. Parameters dialog box by clicking on the OK button. Choose Start from the Simulation menu and watch the traces of the Scope block's input as in Figure 16.

Click on the binocular symbol (Auto scale) for graph automatic scaling. Figure 17 will appear (ignore the format of window's appearance).

Page 13 of 15

The simulation stops when it reaches the stop time specified in the Simulation Parameters dialog box or when you choose Stop from the Simulation menu or press the Stop button on the model window's) toolbar (Windows only). STEP 12 To save this model, choose Save from the File menu and enter a filename and location. That file contains the description of the model. STEP 13 To terminate Simulink and MATLAB, choose Exit MATLAB or type quit in the MATLAB command window. If you want to leave Simulink but don‟t want to terminate MATLAB, just close all Simulink windows. SIMULATION RESULTS (CO3) 1. Obtain the output amplitude values of the original Sine Wave and its integration respectively. 2. Set the simulation stop time parameter to 20 seconds. Record the results. 3. Set the simulation start time parameter to 10 seconds. Record the results. 4. Set the amplitude of Sine Wave to 5. Record the results.

Page 14 of 15

ACTIVITY Obtain the system step response by using Simulink.

14.145 Step Gain

1 s2 +1.204s+2.829 Transfer Fcn

1 s+5 Transfer Fcn1 Scope

STEPS 1) By using Simulink, build a model as shown in Figure 18 above. 2) Simulate the model and record your results.

6.0 DISCUSSION SlMULATION RESULT 1. Set the simulation stop time parameter to 20 seconds. Record the results. 2. Set the simulation start time parameter to 10 seconds. Record the results. 3. Set the source to Sine Wave. Record the results. 7.0 CONCLUSION List out what you have learned from this experiment. 10.0 REFERANCE [1] Nise, Norman S., Control Systems Engineering, 4rd editions, John Wiley, 2000. ISBN: 0471366013 Dorf, R.C. & Bishop, R.H. Modern Control Systems, Addison Wesley (1995) (7th. Edn,) ISBN: 0201845598 Using Simulink Version 6 Using Matlab Version 6

[2]

[3] [4]

Page 15 of 15

- Dynamic Deformation in Mre Driven by Magnetic Field , Gy Zhou, 2003
- lect week 2 (sem 2 2011..2012)
- lect week 2 (sem 2 1011..2012)
- Pen Gen Alan Kepada Sistem Instrumentasi Latest (Sem 2 2011.2012)
- Pen Gen Alan Kepada Sistem Instrumentasi Latest (Sem 2 2011.2012)
- Lab 3
- Lab 4
- Rise Time
- Lab 2
- Step Response of a First and Second Order System
- Time Response Control System
- Block Diagram Manipulation
- Mathematical Modelling
- Lab 3 Sheet Refrigeration Unit - 25 Sep 11
- Lab 3 Sheet Refrigeration Unit - 25 Sep 11
- Lab 3 Sheet Air Compressor Unit - 25 Sep 11
- Lab 3 Sheet Shearing Force-21Sep11
- Lab 3 Sheet Buckling-21Sep11
- Lab 3 Sheet Bending-21Sep11
- Lab III v Notch Cover
- Lab Sheet for v-notch 21 Sept 2011
- Lab III Pelton Wheel Cover
- LAB SHEET for Pelton Wheel 21 Sept 2011
- LAB SHEET for Centrifugal Pump (I)

Sign up to vote on this title

UsefulNot usefulLAB MATLAB for emm4423

LAB MATLAB for emm4423

- EE Assign 2
- control-1
- z Transform and Inverse z & Pole Zero
- CE Lab Report 01
- 13032847790
- Transfer Functions
- linear system analysis
- Chapter 3 Control
- Polynomial
- Chapter 3
- Control Lab
- Brief MATLAB Notes
- An Introduction to Control Theory Applications With Matlab
- bodee
- ece131l exp2
- Feedback Laboratory Exercise 3
- book.pdf
- feedlab0405_1_exp3
- Algebra Workbook
- Bode Plot Examples
- Bode Plot Examples
- math test
- Bode Plots
- Converting Between System Representations
- MATLAB Basic Commands
- Transfer Functions
- DSP-lab4
- J. Basic. Appl. Sci. Res., 1(7) 617-621, 2011
- Basic electrical engineering 2
- Polynomial Solver
- Lab 1

Are you sure?

This action might not be possible to undo. Are you sure you want to continue?

We've moved you to where you read on your other device.

Get the full title to continue

Get the full title to continue reading from where you left off, or restart the preview.

scribd