EEL2216 Control Theory CT2: Frequency Response Analysis 1. Objectives (i) To analyse the frequency response of a system using Bode plot. (ii) To design a suitable controller to meet frequency domain and time domain performance criteria. 2. Introduction The frequency response is a representation of a system's response to sinusoidal inputs at varying frequencies. The output of a linear system to a sinusoidal input is a sinusoid of the same frequency but possibly with a different magnitude and phase. The frequency response is defined as the measure of any system's response at the output to a signal of varying frequency (but constant amplitude) at its input. In this lab session, we will see how we can use the open loop frequency response of a system to predict its behaviour in closed loop. To plot the frequency response, we create a vector of frequencies (varying between zero or dc and infinity) and compute the value of the system s transfer function at these frequencies. If G(s) is the open loop transfer function of a system and ω is the frequency vector, we then plot G(jω) vs. ω. Since G(jω) is a complex number, we can plot both its magnitude and phase (the Bode plot) or its position in the complex plane (the Nyquist plot). Bode plot A Bode plot is the representation of the magnitude and phase of G(jω) (where the frequency vector ω contains only positive frequencies). To see the Bode plot of a transfer function, you can use the SCILAB bode command. The standard bode command in SCILAB plots the horizontal axis in Hz. (Of course we know that by using the relationship ω = 2πf we can easily convert our results to frequency in rad/s if required). Open a SciNotes editor to key in the codes. num = 100; den = (s^3+9*s^2+30*s+40); tf = num/den; ansys = syslin('c',tf); bode(ansys,0.1,100); The above codes should display the Bode plots for the transfer function 100 G ( s) =. Please note that the frequency is in logarithmic scale, the magnitude 3 2 s + 9s + 30s + 40 is given in decibels (top) and the phase is given in degrees (bottom). Note: Decibel is defined as 20 log10 ( G(jω) ). 1
0 Magnitude (db) -50-100 10-1 10 0 10 1 10 2 Frequency (Hz) -50 Phase (degree) -100-150 -200-250 10-1 10 0 10 1 10 2 Frequency (Hz) Gain margin and phase margin Figure 1 The gain margin is defined as the change in open loop gain required to make the closed loop system unstable. Systems with greater gain margins can withstand greater changes in system parameters before becoming unstable in closed loop. Keep in mind that unity gain in magnitude is equal to a gain of zero in db. On the Bode plot, the gain margin is the difference between the magnitude curve and 0dB at the phase crossover frequency, Wpc. Wpc is the frequency that gives us a phase of -180 degrees. The phase margin is defined as the change in open loop phase shift required to make a closed loop system unstable. The phase margin also measures the system's tolerance to time delay. On the Bode plot, the phase margin is the difference in phase between the phase curve and -180 degrees at the gain crossover frequency, Wgc. Wgc is the frequency that gives us a gain of 0dB. 2
We can find the gain and phase margins for a system directly using SCILAB. To obtain the phase crossover frequency and gain margin, type [gm,wpc]= g_margin(ansys) whereas to obtain the gain crossover frequency and phase margin, type [pm,wgc] = p_margin(ansys) For the current example, you should get gain margin = 7.23dB, phase crossover frequency = 0.872Hz, phase margin = 37.6 degrees and gain crossover frequency = 0.579Hz. Additionally, the command show_margins(ansys) will show the margins on the Bode plot but will not display their numerical values, as shown in Figure 2. 0 Magnitude (db) -50-100 -150-200 10-3 10-2 10-1 10 0 10 1 10 2 10 3 Frequency (Hz) 0 Phase (degree) -100-200 -300 10-3 10-2 10-1 10 0 10 1 10 2 10 3 Frequency (Hz) Figure 2 3
Adding gain shifts the magnitude plot upwards. Now suppose you add a gain of 50 to the original system, by entering the command bode(50*ansys,0.1,100); You should get the plot shown below. Figure 3 As you can see the phase plot is exactly the same as before, and the magnitude plot is shifted up by 34dB (gain of 50). The phase margin is now about -60 degrees. A negative value for either the gain margin or the phase margin indicates that the closed loop is unstable. Bandwidth frequency The bandwidth frequency is defined as the frequency at which the closed loop magnitude response is equal to -3 db. However, when we design via frequency response, we are interested in predicting the closed loop behaviour from the open loop response. Therefore, we will use a second-order system approximation and say that the bandwidth frequency equals the frequency at which the open loop magnitude response is between -6 and -7.5dB, assuming that the open loop phase response is between -135 degrees and -225 degrees. In order to illustrate the importance of the bandwidth frequency, we will show how the output changes with different input frequencies. We will find that sinusoidal inputs with frequency less than Wbw (the bandwidth frequency) are tracked reasonably well by the system. Sinusoidal inputs with frequency greater than Wbw are attenuated (in magnitude) by a factor of 0.707 or greater (and are also shifted in phase). 4
Let's say that we have the following closed loop transfer function representing a system: 1 G CL ( s) = 2 s + 0. 5s + 1 First of all, find the bandwidth frequency from the Bode plot by typing num = 1; den = (s^2+0.5*s+1); tf = num/den; ansys = syslin('c',tf); bode(ansys,0.01,1); You should get the plot in Figure 4. Figure 4 Since this is the closed loop transfer function, the bandwidth frequency is the frequency corresponding to a gain of -3 db, which is approximately 1.4 rad/s or 0.22Hz. We can also read from the plot that for an input frequency of 0.3 rad/s or 0.047Hz, the output sinusoid should have a magnitude of about one and the phase should be shifted by a few degrees behind the input. For an input frequency of 3 rad/s or 0.47Hz, the output magnitude should be about -20dB (or 1/10 of the input) and the phase should be nearly -180 degrees (almost out of phase with the input). We can use the csim command to simulate the response of the system to sinusoidal inputs. First, consider a sinusoidal input with a frequency lower than Wbw. We must also keep in mind that we want to view the steady-state response. Therefore, we will modify the axes in order to 5
see the steady-state response clearly (ignoring the transient response). w=0.3; num = 1; den = (s^2+0.5*s+1); t=linspace(0,100,1000); tf = num/den; u = sin(w*t); ansys = syslin('c',tf); y = csim(u,t,ansys); plot2d(t,[u' y']); 1.2 1 0.8 0.6 0.4 0.2 Amplitude 0-0.2-0.4-0.6-0.8-1 -1.2 0 10 20 30 40 50 60 70 80 90 100 Time (s) Figure 5 Note that the output (blue) tracks the input (black) fairly well; it is a few degrees behind the input as expected. However, if we set the frequency of the input higher than the Wbw for the system, we get a very distorted response (with respect to the input). To do this change the codes replacing w=0.3 with w=3 and run the codes. You will find that the magnitude is about 1/10 that of the input, as predicted, and that it is almost exactly out of phase (180 degrees behind the input). Feel free to experiment and view the response for several different frequencies, and see if they match the Bode plot. 6
Closed loop performance In order to predict closed loop performance from open loop frequency response, we need to have several concepts clear: The system must be stable in open loop if we are going to design via Bode plots. If the gain crossover frequency is less than the phase crossover frequency (i.e. Wgc < Wpc), then the closed loop system will be stable. For second-order systems, the closed loop damping ratio is approximately equal to the phase margin divided by 100 if the phase margin is between 0 and 60 degrees. We can use this concept with caution if the phase margin is greater than 60 degrees. A very rough estimate that you can use is that the bandwidth is approximately equal to the natural frequency. 3. Example system Let us use the concepts above to design a controller for the following system r e Controller u Plant y + GC(s) G(s) - where 10 G( s) = 125. s + 1. Figure 6 The design must meet the following specifications: Zero steady-state error. Settling time must be less than 2 seconds. Phase margin must be at least 30 degrees. 4. Procedures 4.1 Original system without controller (i) In order to plot the Bode plot, create an SCE-file with the following code: num = 10; den = (1.25*s+1); tf = num/den; ansys = syslin('c',tf); bode(ansys,0.01,100); (ii) Check the phase margin and gain crossover frequency and record them in Table 1 (row 1). (iii) Check the step response plot by adding the following two lines of code into the command window (after closing your Bode plot): 7
t=linspace(0,0.5,100); cl_ansys = ansys/. 1; //this implements negative unity feedback stepresp=csim('step',t,cl_ansys); plot2d(t,stepresp); xgrid(); Note that X = G/.H evaluates X = G/(1 + GH). 4.2 System with integral controller (i) Incorporate an integral term to yield zero steady-state error for a step input. Change your SCE-file to the following (this adds an integral term but no proportional term): K=1; num = 10; den = (1.25*s+1); numi = K; deni = s; tf = (numi/deni)*(num/den); ansys = syslin('c',tf); bode(ansys,0.01,100); (ii) Study the Bode plot and record the phase margin and gain crossover frequency in Table 1 (row 2). (iii) Plot the step response by adding the following lines to your SCE-file: t=linspace(0,15,100); cl_ansys = ansys/. 1; stepresp=csim('step',t,cl_ansys); plot2d(t,stepresp); xgrid(); (iv) Study the step response plot and record the steady-state error and settling time in Table 1 (row 2). You may change both the x-axis and y-axis limits for better view. 4.3 System with proportional-integral controller (i) In order to improve phase margin, we add a zero at s = -1. Thus we now have a PI K( s + a) controller with the following form of transfer function G C ( s) =, where a = 1. s Change your SCE-file to the following: K=1; num = 10; den = (1.25*s+1); numi = K*(s+1); deni = s; tf = (numi/deni)*(num/den); ansys = syslin('c',tf); bode(ansys,0.01,100); (ii) Obtain the step response plot as well. Study the Bode plot and step response plot. Record the results in Table 1 (row 3). (iii) Try to obtain a higher bandwidth frequency without changing the phase margin too much. 8
This can be achieved by increasing the gain. This will change the gain but the phase will remain the same. By trial and error, change a few gain values and study the Bode plot and step response plot. Record the relevant information in Table 1. Table 1 Steadystate error Settling time (s) 4.1 Original system 9% 0.45s 4.2 With integral controller 4.3 Adding a zero Changing the gain G1 = value. Record G2 = additional gain G3 (not inclusive of = original gain). Phase margin (degrees) Gain crossover frequency (Hz) 5. Exercises Refer to the on-the-spot assessment sheet. 6. Discussion In this lab, you have learned how to analyse the frequency response of a system using Bode plot. In particular, you have seen how to obtain the gain margin and phase margin from the Bode plot. You have also learnt how to design a suitable controller to meet frequency domain and time domain performance criteria. In general, we would like to have large gain margin and phase margin, to ensure that the closed loop system is more stable in the presence of noise (from the environment and from the sensors). In addition to this, we prefer a design with small settling time and no steady-state error. 7. Assessment 1. There will be an on-the-spot assessment for both CT1 and CT2. This will contribute 5% for CT1 and 5% for CT2. 2. There is no laboratory report required for CT1 and CT2. There will be a separate lab design project which contributes another 5% to your final marks. Please check announcement on MMLS regarding this. 9