matlab vezbe

5
MATLAB Exercise - Control Engineering 1 © w t norris MATLAB Exercise : Tuesday 11 September 2007 MATLAB Exercise - Control Engineering 2007 Submit a brief write up showing your plots and comments on them; compare with theory where you can. Q1 is base on Examples Cont B. It may be helpful if you append or otherwise give your scripts which must include comments on what is being done. These can be Copied from MATLAB and then Pasted into Word. Q1 Consider a second order transfer function :– T(s) = 16 s 2 + 2s + 16 Dont forget to make a new figure number after each stage, AND record figure numbers and what they show in your Lab Note Book a) Determine the num and den vectors by inspection and make a TF object sys1= tf(num, den) b) Make a Bode plot Use »bode(sys) or »bodeplot (num,den,fmain,fmax, datapoints) c) Make a pole zero plot Use »pzmap1(num, den) or »pzmap(sys1) d) Examine impulse response »impulse(sys1) e) Examine step response use »step(sys1, tfinal) You may need to experiment to get a good tfinal (i) determine final value You can do this from the equation and the Final Value Theorem. Check it is confirmed by the simulation. (ii) determine the fractional overshoot and the time to maximum overshoot Use »[t, v]= step(sys1, tfinal) and then » [vmax, tmax]= max(v)

Upload: admicicmail

Post on 25-Nov-2015

12 views

Category:

Documents


4 download

DESCRIPTION

Vezbe matlab

TRANSCRIPT

  • MATLAB Exercise - Control Engineering 1

    w t norris MATLAB Exercise : Tuesday 11 September 2007

    MATLAB Exercise - Control Engineering 2007

    Submit a brief write up showing your plots and comments on them; compare with theorywhere you can. Q1 is base on Examples Cont B.

    It may be helpful if you append or otherwise give your scripts which must includecomments on what is being done. These can be Copied from MATLAB and then Pasted into

    Word.

    Q1 Consider a second order transfer function : T(s) = 16s2 + 2s + 16

    Dont forget to make a new figure number after each stage, AND record figurenumbers and what they show in your Lab Note Book

    a) Determine the num and den vectors byinspection and make a TF object

    sys1= tf(num, den)

    b) Make a Bode plot Use bode(sys) orbodeplot (num,den,fmain,fmax, datapoints)

    c) Make a pole zero plot Use pzmap1(num, den)or pzmap(sys1)

    d) Examine impulse response impulse(sys1)e) Examine step response use step(sys1, tfinal)

    You may need to experiment to get a goodtfinal

    (i) determine final value You can do this from the equation and theFinal Value Theorem. Check it is confirmedby the simulation.

    (ii) determine the fractional overshootand the time to maximumovershoot

    Use [t, v]= step(sys1, tfinal)and then

    [vmax, tmax]= max(v)

  • MATLAB Exercise - Control Engineering 2

    w t norris MATLAB Exercise : Tuesday 11 September 2007

    (iii) determine the time to get within2% of final value.

    Note t(40) is the fortieth time point. t(40:80) is a vector of the 40th

    to 80th time points.

    Determine length of t and v vectors.

    dev = abs(v finalvalue); % the unsigneddeviation from the final value.

    Make a plot over a range of t . E.g. :

    plot(dev(40:90 ),t(40:90))Experiment with the range so that you seethe 2% deviation area clearly. You may alsoue "zoom" as described at the end ofQ2(a)(iii)Detail on how to read points off of the plot -see next page.

    To read off the graph: in the Command Window [t, dev] = ginput;Return

    Then cursor wires appear when the pointer is over the plot Move to points where dev 2%.Click. This may be repeated. When done return to Command Window and

    Return.

    The values at the marked points are listed.

    f) plot the ramp responseand compare with theinput. Note the offset..

    Set t= 0: .01: tfinal;

    Then the ramp, u = t;

    lsim[sys1, u, t] %gives the response.hold onplot(u,t)hold off

  • MATLAB Exercise - Control Engineering 3

    w t norris MATLAB Exercise : Tuesday 11 September 2007

    Q 2. Lead Lag correction Dont forget to make a new figure number aftereach stage

    Consider the unity feedback system;

    GR E C+-

    Ks(s + 6)(s + 10)

    a) Do his exercise with an M-File scriptFor K = 1000 make

    i) TF object of the "G" box. I.e., use say sys21=tf(num, den).ii) a Nyquist plot of "GH" noting that H = 1 fro the unity feedback. You will need to use

    [re, im, w] = nyquist(sys21, {wmin, wmax}] % you get no figure yet.and then

    plot[re, im]hold onplot[[remin,remax],[0,0], '- - ') % to make a horizontal dotted line through im = 0plot([-1,-1],[immin,immax],'- -') % to make a vertical dotted line through re = -1hold off

    By trial and error in choosing wmin & wmax you should get a good graph around the 1point and see that the curve wraps round re = -1 : this is a sign of instability.

    OR you can use Zoom. See help zoom for more detail. But a procedure is this:-

    1. Having selected a figure then in the Command Cindow enter zoom on.2. Go back to the figure and with the cursor outline to area you wish to zoominto.3. Go back to the Command window and enter zoom off4. The figure is now with the zoomed in area alone.

    iii) using 'feedback' make a TF of the response of the whole closed loop system, say"sysall21". Since this is a unity feedbacl system you enter

    sysall=feedback(sys21,[1])iv) make a step response of the system. Note that is has zero offset ( there is a pure

    integration in G) but is unstable. Try different times for tfinal. To get more detail ifthe curve is rather rough specify the time steps, thus

    step(sysall21, 0:0.1:20)which will give time steps at an interval of 0.1 over the range t=0 to t=20.

    v) make a num, den set for the overall transfer function:[num, den]=tfdata[sysall21,'v'];

  • MATLAB Exercise - Control Engineering 4

    w t norris MATLAB Exercise : Tuesday 11 September 2007

    The 'v' is needed! Put in the semi-colon too: you already have the data.

    The try pzmap1[num, den]to get a pole-zero plot and values of the poles. Observe the values of the poles.

    vi) Examine the denominator of the overall transfer function and use the Hurwitz criterion toassess the stability of the system.

    b) Repeat with K = 900. Use new numbers for the figures but you can adopt the Scriptused in part (a).c) Make just a step response and a pole-zero plot when K = 192d) Introduce Lag-Lead compensation. The values used below have been deduced elsewhere(Nise, Control Systems Engineering, p 482 et seq.)

    i) Make a Bode plot and a pole zero plot of a lead compensator

    HLead = s+6

    s+2901 ; notice that this cancels a pole in the original.

    ii) Make a Bode plot and a pole zero plot of a lag compensator

    HLead = s+004713s+0001

    How are they different in character. Why are they so named do you think?

    iii) The system below incorporates the lag and lead compensators given above

    GR E C+-

    K(s + 0.04713)s(s + 10)(s + 29.101)(s + 0.01)

    Repeat the steps of (a) but with the transfer function just given in (d)(iii) and withK = 1971. This value for K in the uncompensated system would have been very unstable.

    e) Make a new Script incorporating earlier ones so that you can compare the step responseof the original system with K = 192 and the compensated system found in (d).. Use ' holdon'. Comment. This is the flowering of the use of compensation.

    Additional ideas.

    1. If you are curious and have time you may like to look at step responses of the originaluncompensated system with other values of K, say around K = 192. Can you meet theperformance of the compensated system ?

    2. Make a phase plot. This is a trace of the velocity or one might say, gradient, againstdisplacement. It can be made by remembering that the inpulse function is the derivative ofthe step function And moreover the step function is the derivative of the ramp function. Canyou justify those statements from your knowledge of Laplace transforms ?Thus a phase plot of the step response of a system sys can be made this way

    [y1,t]=step(sys, 0:.01:5); % Gives vectors of displacment and time.

  • MATLAB Exercise - Control Engineering 5

    w t norris MATLAB Exercise : Tuesday 11 September 2007

    [dy1,t]=impulse(sys, 0:.01:5); % Gives vectors of velocity of the step and time.figure(15) % New figureplot(y1,dy1) % Gives the phase plot, velocity or gradient against

    position.