Introduction to MATLAB

3
Chapter 3 Lab 3 - Introduction to MATLAB 3.1 Introduction You have probably noticed that any control problem of degree higher than two can get numerically very complex. Luckily, there are computer programs that make the task extremely efficient. The following is a brief introduction to MATLAB Program, Version 7.0. 3.2 MATLAB Basics Now let’s use MATLAB. Try to enter the transfer function: G(s)= 1 s(s + 1)(s + 2) The easiest way to do this is to just enter it symbolically. >>s=’s’; >>g=tf([1],[1 3 2 0]); >>g Transfer function: H(s)= 1 s 3 +3s 2 +2s There are other variations on the ENTER command. Use the HELP function to find out! You can invoke HELP by typing: >>help rltool %SISO Design >>help sisotool The SISO Design Tool is a graphical user interface (GUI) that facilitates the design of compensators for single-input, single-output feedback loops. The SISO Design Tool allows you to iterate rapidly on your designs and perform the following tasks: Manipulate closed-loop dynamics using root locus techniques. Shape open-loop Bode responses. Add compensator poles and zeros. Add and tune lead/lag networks and notch filters. Inspect closed-loop responses (using the LTI Viewer). Adjust phase and gain margins. Convert models between discrete and continuous time. Importing Models into the SISO Design Tool 25

description

Chapter 3

Transcript of Introduction to MATLAB

Page 1: Introduction to MATLAB

Chapter 3

Lab 3 - Introduction to MATLAB

3.1 Introduction

You have probably noticed that any control problem of degree higher than two can get numerically verycomplex. Luckily, there are computer programs that make the task extremely efficient. The following is abrief introduction to MATLAB Program, Version 7.0.

3.2 MATLAB Basics

Now let’s use MATLAB. Try to enter the transfer function:

G(s) =1

s(s + 1)(s + 2)

The easiest way to do this is to just enter it symbolically.

>>s=’s’;>>g=tf([1],[1 3 2 0]);>>g

Transfer function:

H(s) =1

s3 + 3s2 + 2s

There are other variations on the ENTER command. Use the HELP function to find out! You can invokeHELP by typing:

>>help rltool %SISO Design>>help sisotool

The SISO Design Tool is a graphical user interface (GUI) that facilitates the design of compensatorsfor single-input, single-output feedback loops. The SISO Design Tool allows you to iterate rapidly on yourdesigns and perform the following tasks: Manipulate closed-loop dynamics using root locus techniques.Shape open-loop Bode responses. Add compensator poles and zeros. Add and tune lead/lag networks andnotch filters. Inspect closed-loop responses (using the LTI Viewer). Adjust phase and gain margins. Convertmodels between discrete and continuous time.

Importing Models into the SISO Design Tool

25

Page 2: Introduction to MATLAB

26 CHAPTER 3. LAB 3 - INTRODUCTION TO MATLABIf you type sisotool at the MATLAB prompt, an empty SISO Design Tool opens. You can import

the DC motor model by selecting Import Model under the File menu. This opens the Import System Datadialog box.

Impulse Response

The impulse response of a dynamical model is the output signal that results when the input is an impulse,i.e., u(t) is zero for all values of t except t=0, where u(0)=1. It can be computed as in the equation followingARX, by letting t be equal to 0, 1, 2, ... and taking y(-T)=y(-2T)=0 and u(0)=1. The step response is theoutput signal that results from a step input, i.e., u(t) is zero for negative values of t and equal to one forpositive values of t.

The impulse and step responses together are called the model’s transient response. The frequency re-sponse of a linear dynamic model describes how the model reacts to sinusoidal inputs. If we let the inputu(t) be a sinusoid of a certain frequency, then the output y(t) will also be a sinusoid of this frequency. Theamplitude and the phase (relative to the input) will, however, be different.

This frequency response is most often depicted by two plots; one that shows the amplitude change asa function of the sinusoid’s frequency and one that shows the phase shift as function of frequency. This isknown as a Bode plot.

Zeros and Poles

The zeros and the poles are equivalent ways of describing the coefficients of a linear difference equationlike the ARX model. The poles relate to the ”output-side” and the zeros relate to the ”input-side” of thisequation. The number of poles (zeros) is equal to the number of sampling intervals between the most andleast delayed output (input).

In the ARX example in the beginning of this section, there are consequently two poles and one zero.SISOTOOL(G) specifies the plant model G to be used in the SISO Tool. Here G is any linear model createdwith TF, ZPK, or SS.

SISOTOOL(G,C) further specifies an initial value for the compensator C. Similarly, SISOTOOL(G,C,H,F)supplies additional models for the sensor H and the prefilter F.

SISOTOOL(VIEWS) or SISOTOOL(VIEWS,G,...) specifies the initial configuration of the SISO Tool. VIEWScan be any of the following

strings (or combination thereof):’rlocus’ %Root locus plot’bode’ %Bode diagram of the open-loop response’nichols’ %Nichols plot of the open-loop response’filter’ %Bode diagram of the prefilter F

For example sisotool({’nichols’,’bode’})

Opens a SISO Design Tool showing the Nichols plot and the open-loop Bode Diagram. You can alsouse an extra argument OPTIONS (structure) to specify any of the following options:

OPTIONS.Location%Location of C (’forward’ for forward path,’feedback’ for return path)OPTIONS.Sign

%Feedback sign (-1 for negative, +1 for positive)

See also LTIVIEW, RLOCUS, BODE, NICHOLS.

Page 3: Introduction to MATLAB

3.3. PROCEDURE 273.3 Procedure

1. Run through the tutorial given above. Do not turn in anything from the tutorial for the lab report.Perform the following procedure in MATLAB. You do not have to obtain a hardcopy for everything,we indicate where we want printouts.

2. Enter the transfer function:G(s) =

1s(s + 1)(s + 2)

3. Plot the bode plot for the open-loop system and determine the phase margin. Obtain a hardcopy.

4. Plot the root locus and use the cursor function to determine the gain at which the damping ratio ζ(zeta) of the dominant poles is 0.6. For what range of gain will the system remain stable? Obtain ahardcopy. Use CTRL-arrows to move faster, and ”x” to change cursor in root locus graph. (”k” is thegain)

5. Now create a gain compensated system by multiplying the transfer function G(s) by the gain found instep 4 which gives a damping ratio of 0.6.

6. Simulate the closed-loop step response of the gain compensated system from above and from the graph(use the cursor function) determine the rise time, settling time, and percent overshoot. Obtain ahardcopy from MATLAB, be sure to label your plots.

7. Simulate the steady-state error to a ramp input for the gain compensated closed loop system. (Hint,first obtain a transfer function for the error output to a ramp input. Then simulate it using openimpulse response. Calculate the steady-state error to a ramp by hand and see if it agrees with thecomputer. Obtain a hardcopy.

8. Using MATLAB, plot the open-loop Bode plot for your modeled motor-tach system using the parame-ters you determined in Lab 2 with Ka = 2. Obtain a hardcopy, find the phase margin, and indicate iton the output plot.

9. Plot the closed-loop Bode plot for your modeled motor-tach system from Lab 2. (remember to initializewith FREQ) Use Ka = 2. Label the peaking frequency and amplitude, obtain a hardcopy.

3.4 Pre-lab

1. Calculate (by hand) the closed-loop steady-state error to a ramp for the system given in step 2 of theprocedure. (Hint: Use the final value theorem.)

2. What is meant by system type number? (Hint: See Linear Controls text.)

3. What is meant by phase margin? (Hint: See Linear Controls text.)

3.5 Report

Include answers to the following:

1. What is necessary to do to the system above to reduce the steady-state error to a ramp input? Whatis necessary to achieve zero steady-state error to a ramp? Explain.