# Frequency Response for Control Systems

Publish Date: Nov 29, 2010 | 8 Ratings | 3.62 out of 5 |  PDF

## Overview

This tutorial shows how to plot the frequency response of a system, using LabVIEW and the LabVIEW Control Design and Simulation Module.

These tutorials are based on the Control Tutorials developed by Professor Dawn Tilbury of the Mechanical Engineering department at the University of Michigan and Professor Bill Messner of the Department of Mechanical Engineering at Carnegie Mellon University and were developed with their permission.

### 1. Frequency Response

The frequency response method may be less intuitive than other methods you have studied previously. However, it has certain advantages, especially in real-life situations such as modeling transfer functions from physical data.

The frequency response is a representation of the 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 with a different magnitude and phase. The frequency response is defined as the magnitude and phase differences between the input and output sinusoids. In this tutorial, we will see how we can use the open-loop frequency response of a system to predict its behavior 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 plant transfer function at those frequencies. If G(s) is the open loop transfer function of a system and w is the frequency vector, we then plot G(j*w) versus w. Since G(j*w) 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).

### 2. Bode Plots

As noted above, a Bode plot is the representation of the magnitude and phase of G(j*w) (where the frequency vector w contains only positive frequencies).

### LabVIEW Graphical Approach

To see the Bode plot of a transfer function, you can use the CD Bode VI, located in the Frequency Response section of the Control Design palette.

Figure 1: Creating a Bode Plot (Download)

### LabVIEW MathScript Approach

Alternatively, you can use the following m-file code in the MathScript Window (Tools » MathScript Window):

num = 50;

den = [1 9 30 40];

sys = tf(num,den);

bode(sys)

### Result

With either approach, we display the transfer function and Bode plots for the system. Figure 2 shows the front panel of the VI that was built in Figure 1. Change the terms in the numerator and denominator to observe the effect on the system’s Bode plots.

Figure 2: Bode Plots in LabVIEW

Note the axes of the plots in Figure 2. The frequency is on a logarithmic scale, the phase is given in degrees, and the magnitude is given as the gain in decibels. A decibel is defined as 20*log10 ( |G(j*w)| ) .

### 3. Gain and Phase Margin

Let's say that we have the following system:

Figure 3: A Closed-Loop System

In this system, K is a variable (constant) gain and G(s) is the plant under consideration. The gain margin is defined as the change in open loop gain required to make the 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.

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. If there is a time delay greater than 180/Wpc in the loop (where Wpc is the frequency where the phase shift is 180 deg), the system will become unstable in closed loop. The time delay can be thought of as an extra block in the forward path of the block diagram that adds phase to the system but has no effect the gain. That is, a time delay can be represented as a block with magnitude of 1 and phase w*time delay (in radians/second).

For now, we won't worry about where all this comes from and will concentrate on identifying the gain and phase margins on a Bode plot.

The phase margin is the difference in phase between the phase curve and -180 degrees, at the point corresponding to the frequency that gives us a gain of 0dB (the gain cross over frequency, Wgc). Likewise, the gain margin is the difference between the magnitude curve and 0dB at the point corresponding to the frequency that gives us a phase of -180 deg (the phase cross over frequency, Wpc).

Figure 4: Gain and Phase Margins

One nice thing about the phase margin is that you don't need to re-plot the Bode in order to find the new phase margin when changing the gains. If you recall, adding gain only shifts the magnitude plot up. This is the equivalent of changing the y-axis on the magnitude plot. Finding the phase margin is simply the matter of finding the new cross-over frequency and reading off the phase margin.

To observe this effect, first look at the Bode plots in Figure 4. You should see that the phase margin is about 100 degrees.

Now suppose you added a gain of 100.

### LabVIEW Graphical Approach

To achieve this in a VI, add a second CD Construct Transfer Function Model VI to your block diagram from Figure 1. Create a constant input to the numerator terminal, and enter 100 into the first cell of this array. Next, add the CD Series VI to the block diagram (from the Model Interconnection section of the Control Design palette) and connect both transfer function models to the inputs of the CD Series VI. Connect the Series Model output of the CD Series VI to the CD Bode and CD Draw Transfer Function VI’s as before.

Figure 5: Bode Plot of a System with Gain (Download)

### LabVIEW MathScript Approach

If you used m-file code to model the system, enter the command bode(100*sys) into the MathScript Window.

### Result

After adding a gain of 100, you should see the following plots:

Figure 6: Bode Plots With Gain of100

As you can see, the phase plot is exactly the same as before, and the magnitude plot is shifted up by 40dB (gain of 100). The phase margin is now about -60 degrees. This same result could be achieved if the y-axis of the magnitude plot was shifted down 40dB. To confirm this, look at the Bode plots in Figure 4, find where the curve crosses the -40dB line, and read off the phase margin. It should be about -60 degrees, the same as the Bode plots in Figure 6.

We can also find the gain and phase margins for a system directly in LabVIEW.

### LabVIEW Graphical Approach

Using the VI from Figure 1, replace the CD Bode VI with the CD Gain and Phase Margin VI, found in the Frequency Response section of the Control Design palette. Create indicators for Magnitude Plot, Phase Plot, and Gain and Phase Margins.

Figure 7: Gain and Phase Margin in LabVIEW (Download)

### LabVIEW MathScript Approach

Alternatively, you can use the margin command in the MathScript Window. This command returns the gain and phase margins, the gain and phase cross over frequencies, and a graphical representation of these on the Bode plot. If you used m-file code to model the system, enter the following command into the MathScript Window:

margin(sys)

### Result

Plotting the gain and phase margins returns the graphs shown below in Figure 8.

Figure 8: Gain and Phase Margins

### 4. 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 behavior 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 the open loop phase response is between -135 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).

Let's say that we have the following closed-loop transfer function representing a system:

First, let's find the bandwidth frequency by looking at the Bode plot. (To do this, refer to the VI built in Figure 1 or the corresponding MathScript code.)

Figure 9: Bode Plots

Since this is the closed-loop transfer function, our bandwidth frequency will be the frequency corresponding to a gain of -3 dB. Looking at the plot, we find that it is approximately 1.4 rad/s. We can also read off the plot that for an input frequency of 0.3 radians, the output sinusoid should have a magnitude about one and the phase should be shifted by perhaps a few degrees (behind the input). For an input frequency of 3 rad/sec, the output magnitude should be about -20dB (or 1/10 as large as the input) and the phase should be nearly -180 (almost exactly out-of-phase).

First, consider a sinusoidal input with a frequency lower than Wbw.

### LabVIEW Graphical Approach

We can use a Simulation Loop (from the Simulation palette) to simulate the response of the system to sinusoidal inputs. Refer to the block diagram in Figure 10 below to build this system.

Figure 10: Linear Simulation in LabVIEW (Download)

### LabVIEW MathScript Approach

Alternatively, we can use the lsim command in the MathScript Window to achieve the same result.

w = 0.3;

num = 1;

den = [1 0.5 1];

sys = tf(num,den);

t = 0:0.1:100;

u = sin(w*t);

[y,t] = lsim(sys,u,t);

plot(t,y,t,u)

### Result

We must keep in mind that we want to view the steady state response. Therefore, we ignore the transient response when we look at these plots.

Figure 11: Linear Simulation of a System (Download)

Note that the output (white) tracks the input (red) fairly well; it is perhaps a few degrees behind the input as expected.

However, if we set the frequency of the input higher than the bandwidth frequency for the system, we get a very distorted response (with respect to the input). Observe the effects of changing the frequency from 0.3 to 3.

### LabVIEW Graphical Approach

Increase the input signal frequency to 3, using the front panel control of your VI.

### LabVIEW MathScript Approach

Enter the following code into the MathScript Window:

w = 3;

num = 1;

den = [1 0.5 1];

sys = tf(num,den);

t = 0:0.1:100;

u = sin(w*t);

[y,t] = lsim(sys,u,t);

plot(t,y,t,u)

axis([90, 100, -1, 1])

### Result

Figure 12: Linear Simulation of a System, w= 3

Again, note that the magnitude is about 1/10 that of the input, as predicted, and that it is almost exactly out of phase with (180 degrees behind) the input. Feel free to experiment and view the response for several different frequencies w, and see if they match the Bode plot.

### 5. 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 cross over frequency is less than the phase cross over 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.

Let's use these concepts to design a controller for the following system:

Figure 13: A Closed-Loop System

In this system, Gc(s) is the controller, and G(s) is:

The design must meet the following specifications:

• Zero steady state error.
• Maximum overshoot must be less than 40%.
• Settling time must be less than 2 seconds.

There are two ways of solving this problem: one is graphical and the other is numerical. In LabVIEW, the graphical approach is best, so that is the approach we will use. First, let's look at the Bode plot. Use the VI from Figure 1 (or the MathScript Window) to graph the Bode plots for the above transfer function.

Figure 14: Bode Plots

There are several characteristics of the system that can be read directly from this Bode plot. First of all, we can see that the bandwidth frequency is around 10 rad/sec. Since the bandwidth frequency is roughly the same as the natural frequency (for a first order system of this type), the rise time is 1.8/BW = 1.8/10 = 1.8 seconds. This is a rough estimate, so we will say the rise time is about 2 seconds.

The phase margin for this system is approximately 95 degrees. The relation damping ratio = (phase margin)/100 only holds for phase margins less than 60 degrees. Since the system is first-order, there should be no overshoot.

The last major point of interest is steady-state error. The steady-state error can be read directly off the Bode plot as well. The constant (Kp, Kv, or Ka) is found from the intersection of the low frequency asymptote with the w=1 line. Just extend the low frequency line to the w=1 line. The magnitude at this point is the constant. Since the Bode plot of this system is a horizontal line at low frequencies (slope = 0), we know this system is of type zero. Therefore, the intersection is easy to find. The gain is 20dB (magnitude 10). What this means is that the constant for the error function is 10.

The steady-state error for this system is 1/(1+Kp) = 1/(1+10)=0.091. If our system was type one instead of type zero, the constant for the steady-state error would be found in a manner similar to the following:

Figure 15: Finding Constant for Steady-State Error

Let's check our predictions by looking at a step response plot.

### LabVIEW Graphical Approach

This can be achieved in LabVIEW by using the CD Step Response VI (from the Time Response section of the Control Design palette), along with the CD Feedback VI.

Figure 16: Step Response Using Feedback (Download)

### LabVIEW MathScript Approach

Alternatively, you can add two lines of code into the MathScript Window:

sys_cl = feedback(sys,1);

step(sys_cl)

### Result

The resulting graph is shown in Figure 17 below.

Figure 17: Step Response, No Controller

As you can see, our predictions were very good. The system has a rise time of about 2 seconds, has no overshoot, and has a steady-state error of about 9%. Now we need to choose a controller that will allow us to meet the design criteria. We choose a PI controller because it will yield zero steady state error for a step input. Also, the PI controller has a zero, which we can place. This gives us additional design flexibility to help us meet our criteria. Recall that a PI controller is given by Gc(s) =  [K*(s+a)] / s.

The first thing we need to find is the damping ratio corresponding to a percent overshoot of 40%. Plugging in this value into the equation relating overshoot and damping ratio (or consulting a plot of this relation), we find that the damping ratio corresponding to this overshoot is approximately 0.28. Therefore, our phase margin should be at least 30 degrees. From the equation that relates Ts*Wbw to damping ratio, we find that Ts*Wbw ~ 21. We must have a bandwidth frequency greater than or equal to 12 if we want our settling time to be less than 1.75 seconds which meets the design specs.

Now that we know our desired phase margin and bandwidth frequency, we can start our design. Remember that we are looking at the open-loop Bode plots. Therefore, our bandwidth frequency will be the frequency corresponding to a gain of approximately -7 dB.

Let's see how the integrator portion of the PI controller affects our response.

### LabVIEW Graphical Approach

To do this, create system models for both the plant and the PI controller. Connect these models in series with the CD Series VI, and plot the bode plots for the resulting model using the CD Bode VI.

Figure 18: System with PI Controller (Download)

### LabVIEW MathScript Approach

Alternatively, you can use textual code in the MathScript Window to model the system. Change your code to add an integral term but no proportional term.

num = 10;

den = [1.25 1];

plant = tf(num,den);

numPI = 1;

denPI = [1 0];

contr = tf(numPI,denPI);

bode(contr * plant, logspace(0,2))

### Result

The front panel that results from the VI in Figure 18 is shown below, in Figure 19.

Figure 19: PI Controller with Bode Plots

From the graphs here or from the MathScript plot, we see that our phase margin and bandwidth frequency are too small.

We will add gain and phase with a zero. Let's place the zero at 1 for now and see what happens.

### LabVIEW Graphical Approach

Change your VI front panel controls so that the Numerator 2 terms are 1, 1.

### LabVIEW MathScript Approach

Modify your code to look like the following:

num = 10;

den = [1.25 1];

plant = tf(num,den);

numPI = [1 1];

denPI = [1 0];

contr = tf(numPI,denPI);

bode(contr * plant, logspace(0,2))

### Result

Figure 20: Effect of PI Controller with a Zero at 1

It turns out that the zero at 1 with a unit gain gives us a satisfactory answer. Our phase margin is greater than 60 degrees (even less overshoot than expected) and our bandwidth frequency is approximately 11 rad/s, which will give us a satisfactory response. Although satisfactory, the response is not quite as good as we would like.

Therefore, let's try to get a higher bandwidth frequency without changing the phase margin too much. Let's try to increase the gain to 5 and see what happens. This will make the gain shift and the phase will remain the same.

### LabVIEW Graphical Approach

Change your VI controls so that the Numerator 2 terms are 5, 5.

### LabVIEW MathScript Approach

If you are using the MathScript Window, change the numerator of the controller by using the command numPI = 5*[1 1]; in place of the command that was used previously.

### Result

Figure 21: Effect of PI Controller with Gain= 5

That looks really good. Let's look at our step response and verify our results.

### LabVIEW Graphical Approach

As we did in Figure 16, we create a system with a numerator of 1 and add the CD Feedback VI and the CD Step Response VI to our block diagram.

### LabVIEW MathScript Approach

Alternatively, we can add the following two lines to the MathScript Window:

sys_cl = feedback(contr * plant,1);

step(sys_cl)

### Result

Figure 22: PI Controller Step Response (Download )

As you can see, our response is better than we had hoped for. However, we are not always quite as lucky and usually have to play around with the gain and the position of the poles and/or zeros in order to achieve our design requirements.

### Ratings

Rate this document