12
Drawing Bode Plots (The Last Bode Plot You Will Ever Make) Charles Nippert This set of notes describes how to prepare a Bode plot using Mathcad. Follow these instructions to draw Bode plot for any transfer function. In these notes we will draw the Bode plots of a second order transfer function. However, after you have created the sample program, you can easily modify it to plot any transfer function. Therefore, this is the last Bode plot you need to draw from scratch! Another alternative is that you can use these notes to prepare Bode plots of any function merely by using that function, adjusting the scale factors for frequency and the coefficient in the Margin Response. The transfer function you will plot is: () ( )( ) 1 s 02 . 0 1 s 10 2 . 0 s G + + = These notes will use an array of values of frequency to generate arrays of values of amplitude ratio, magnitude ratio and, phase shift. In order to produce a curve that appears smooth, you will use a large number of values of frequency in the arrays. You will then use Mathcad’s plotting feature to draw graphs. You will make log-log plots and log plots that are the customary forms of Bode plots. Begin by Opening Mathcad 1. Open Mathcad in the usual fashion. Create a Range Variable 2. You will now create a Mathcad "range variable". A “range variable” is a variable containing integer values ranging from a low value to an upper value, such as the integers 0, 1, 2, 3, … 50. In you Bode plot, the range variable will be used to create arrays and access the values in individual elements in those arrays as you create the plots. Name your range variable “i”. Type “i” about a half an inch below the top of your work page. The next step is to create the arithmetic assignment sign, (the ":=” symbol). Do this in one of two ways: either: 1. Select "View/Toolbars/Calculator" from the menu. A toolbar will appear. Click on the button. Alternatively, you can 2. Type ":". A small black, rectangle should appear to the right of the “:=” symbol as shown in figure 1. This rectangle is a placeholder and indicates that Mathcad is waiting for more information.

Drawing Bode Plots (the Last Bode Plot You Will Ever Make) Charles Nippert

Embed Size (px)

Citation preview

  • Drawing Bode Plots (The Last Bode Plot You Will Ever Make)

    Charles Nippert This set of notes describes how to prepare a Bode plot using Mathcad. Follow these instructions to draw Bode plot for any transfer function. In these notes we will draw the Bode plots of a second order transfer function. However, after you have created the sample program, you can easily modify it to plot any transfer function. Therefore, this is the last Bode plot you need to draw from scratch! Another alternative is that you can use these notes to prepare Bode plots of any function merely by using that function, adjusting the scale factors for frequency and the coefficient in the Margin Response. The transfer function you will plot is:

    ( ) ( )( )1s02.01s102.0sG ++=

    These notes will use an array of values of frequency to generate arrays of values of amplitude ratio, magnitude ratio and, phase shift. In order to produce a curve that appears smooth, you will use a large number of values of frequency in the arrays. You will then use Mathcads plotting feature to draw graphs. You will make log-log plots and log plots that are the customary forms of Bode plots. Begin by Opening Mathcad 1. Open Mathcad in the usual fashion. Create a Range Variable 2. You will now create a Mathcad "range variable". A range variable is a variable

    containing integer values ranging from a low value to an upper value, such as the integers 0, 1, 2, 3, 50. In you Bode plot, the range variable will be used to create arrays and access the values in individual elements in those arrays as you create the plots. Name your range variable i. Type i about a half an inch below the top of your work page. The next step is to create the arithmetic assignment sign, (the ":= symbol). Do this in one of two ways: either: 1. Select "View/Toolbars/Calculator" from the menu. A toolbar will appear.

    Click on the button. Alternatively, you can 2. Type ":". A small black, rectangle should appear to the right of the := symbol as shown in figure 1. This rectangle is a placeholder and indicates that Mathcad is waiting for more information.

  • Figure 1

    2. Next, indicate the range of the integers. Do this by first typing the lower limit of

    the range, in this case 0. Next, create the range symbol by doing one of the following: 1. Select "View/Toolbars/Matrix". A toolbar will appear. Click on the button. Alternatively you can 2. Type ";" Finally, finish the range variable by typing the upper limit, in this case 100. Should look like figure 2

    Figure 2

    You have now defined a range variable called "i" that contains all the integers

    from zero to 100.

  • Create an Array of Frequencies 3. You will now enter the equation that defines the range of frequencies to be used

    in the Bode plot. Frequency is generally represented by the Greek letter . Move the cursor somewhere below the range variable that you have already created. You can do this by moving the mouse cursor just below the range variable and clicking your left mouse button. You can create Greek letters by selecting "View/Toolbars/Greek" from the menu. A toolbar with Greek letters appears. Type the Greek letter that you wish, in this case .

    4. The value will represent an array of numbers. Each number will be

    represented by a subscript, the value of the first subscript in the array will be zero, the value of the next subscript will be one and, the value of the last (the hundred and first) will be 100. Now create a subscript in one of two ways: 1. Click the button from the Matrix toolbar 2. Type [ in either case, your screen should now resemble Figure 3

    Figure 3

    5. The black rectangle is a placeholder a little lower than the Greek letter and

    slightly to the right. Type the letter i and then enter of the := symbol as you did in step 1 of these notes. The horizontal axis of a bode plot is generally a logarithmic scale. In order to have values of frequency regularly spaced a logarithmic axis, use the following formula:

    Where min = the smallest power of 10 on the Bode plot

    span = the range of the powers of ten. In this sample program, the smallest value of will be 10-5 and the largest value

    will be 105. Type the number 10. Remember to use the ^ symbol to create a superscript. In this case we will use a minimum value of -5 and a span of 10. Enter those numbers in the formula in place of the names so that your finished formula should look like Figure 4

  • Figure 4

    Change the values of the minimum and the span if you wish to change the

    values of the horizontal axis. 6. You will now enter the transfer function given on the first page of these notes.

    Mathcad allows functions that written in the form of

    function_name(variable1, varaible2, . variableN) = mathematical expression Therefore it should be easy to enter the transfer function.

    ( ) ( )( )1s02.01s102.0sG ++=

    Move the mouse cursor just below the formula for frequency. Begin typing the equation. Start with the left side, create the := symbol and type 0.2. Use the / key to create the division. Remember to use an * to indicate every multiplication (between the 10 and the s, the 0.02 and the s and between )(. The finished equation is shown in Figure 5.

    Figure 5

    7. Bode plots are generated from the transfer function by replacing the s terms with

    i. You will not compute the complex values of the transfer function for each frequency, placing them in an array that you will name g. This entire action is done with one equation that define each element in the array g. Use the mouse cursor to move to an area just below the transfer function. Click on the left mouse button and type g. Then create a subscript using either the button or the [

    key. Type i. Next, create the := symbol using either the button or the : key. Finally, type the formula; type G(. You will find the square root symbol all on the calculator toolbar that you can make visible using the "View/Toolbars/Calculator" menu option. Type -1 under the square root sign.

  • Your formula should look like figure 6a. The frequency symbol must appear outside the square root sign and multiplies the square root of minus one. Tap right arrow key twice to move the inverted L cursor from under the square root symbol. The inverted L. cursor embraces the entire square root symbol as shown in figure 6b. Next hit the Asterix. Then hit the button on the toolbar. Create a subscript and type i. Finish with a ). The final equation is shown in figure 6c

    Figure 6a

    After typing -1 Figure 6b

    Tap Right Arrow Key Twice to Move the Cursor OUT OF the Square Root

    Figure 6c Finished!

    Make sure that the frequency is outside of the square root symbol. If you make a mistake, erase the equation and start over.

    8. The amplitude response of a transfer function is simply the magnitude of the

    complex value of transfer function. The array g contains the complex values of the transfer function of evaluated at the wavelengths. We will now use Mathcad's functions to obtain both the magnitude and the angle of the phaser given by gi. Mathcad uses the absolute value symbol to return the magnitude of a complex number. Therefore, finding the amplitude response is simple. Underneath the formula for g create an array named AR to contain the amplitude response for the values of frequency given in the array. Press the absolute value button after creating the := symbol. The button is found on both the Calculator and Matrix toolbars. Move the inverted L. inside the absolute value symbol and type the rest of the letter g. and the subscript i. The finished equation is shown in figure 7

    Figure 7

  • 9. The Margin Response is the Amplitude Response divided by the process gain which is merely the coefficient of the transfer function when it is written with the constant terms will polynomial factors set to one, as illustrated by the sample transfer function. The process gain in this example is 0.2 so the margin response is obtained by dividing the amplitude response by 0.2. This equation is shown in figure 8.

    Figure 8

    10. The equation for phase shift shown in figure 9 uses several Mathcad functions.

    The functions Re(x) and Im(x) return the real and imaginary components of a complex number, respectively. The atan2(x, y) function returns the angle from the x-axis to a line containing the origin and the point (x,y). Results are in radians between and , excluding . Multiply the values returned by atan2 by 180/ to convert to degrees. Enter this equation just below the Margin Response.

    Figure 9

    Draw the Graph 11. Press Enter to leave the last equation. Move the Red Cross cursor to a spot

    below your last equation. From the menu bar choose "View/Toolbars/Graph. The graph toolbar shown in figure 10 will appear.

    Figure 10 The Graph Toolbar

    12. The two-dimensional graph is created by clicking the button in the upper left-hand

    corner of the toolbar. The button looks like a 2-D graph, . Click that button and a graph object will replace the Red Cross cursor. The object is shown in figure 11. The black rectangles on the outer border are "handles" you can "grab" by pressing and holding them with the mouse cursor to change the size and shape of the graph. . The inner, large, empty rectangle shows the size of the graph itself. The solid rectangles that are not attached to any shape our placeholders for the horizontal and vertical axes. The inverted L cursor appears at the horizontal axis.

  • Figure 11 The Graph Object

    13. You will make the elements of the array, , the values for the horizontal axis. If

    the inverted L cursor is not on the horizontal axis placeholder, move the mouse cursor over that placeholder and click the left mouse button. Type i to enter the horizontal axis. Be sure to use the real subscript (the button or the [key). Next, click on the vertical axis placeholder to move the inverted all cursor over it. Mathcad allows you to plot either arrays that have been calculated already or values that are calculated "in place". The vertical axes will disoplay the arrays AR and MR. On the vertical axis type ARi, when you are finished, Mathcad will display a line using the 101 values from AR array and pair them with the appropriate values of i to plot a line. Your graph object should now resemble figure 12.

    Figure 12 After Entering the Horizontal and Vertical Axes

    14. Mathcad only allows one set of values on the horizontal axis. You can plot as

    many arrays on the vertical axis as you wish. If the inverted L. cursor is not at the end of the variable AR, move the mouse cursor over the AR, click the left mouse button and, press the right arrow key until the cursor looks like the one shown in Figure 12. When the inverted L cursor is at the end of the ARi line, type , to create a new placeholder just below it. Your screen should look like figure

    Handle to change the size of the graph.

    Horizontal axis

    Vertical axis

    Plot area

  • 13. Then enter the second variable MRi and press Enter. The graph should resemble figure 13b

    Figure 13a The Vertical Axis

    Figure 13b The Finished Graph

    Modify the Graph 13. You will now make the plot look like a Bode plot by changing the axes from

    Cartesian axis to logarithmic axes. Move the mouse cursor over the graph and click on it once. The border with the handles should appear. Grab the handle in the lower right hand corner with the mouse and drag it down into the right to make the graph larger. Then double-click on the graph with the mouse cursor to call up the graph dialog box that a shown me in figure 14. When the box appears, the "grid lines" and Log Scale options are not checked. Check them now as shown in the figure.

  • Figure 14 X-Y Traces on the Graph Dialog Box

    14. Click the "Traces" tab. This tab allows you to specify the appearance of the lines drawn on the screen. Move the mouse cursor over the line labeled "traced two" and click. The default setting for this line is a role dots. Move the mouse cursor to the pull down tab labeled line and click on "solid. Your screen should appear like figure 15 before you click on solid".

  • Figure 15 The Traces Tab

    15. Click OK to close the dialog. The completed graphic shown in figure 16

    Figure 16 Completed Bode Plot

  • 16. Now plot the phase angle below your first plot by modifying the steps you used to plot the Margin Response and the Amplitude Response as outlined below: 1. Only plot i on the vertical axis 2. In step 14, on the Y-Axis list of check boxes. leave the Log Axis box UNCHECKED

    The phase angle plot is shown in Figure 15

    Figure 15 Phase Plot

    Modifying Your Bode Plots for New Functions SAVE THIS FILE! You can modify your file to give you Bode plots of any transfer function. Here are the things you must do to modify this file. 17. Change the function G(s). Click on this formula and enter your new formula.

    Click on this function. Move the mouse cursor over the equation near the lower right hand side. Press and hold the left mouse button as you drag the cursor to the left until the entire right hand side of the equation up to the := sign is shown in reverse video, as shown in Figure 16. Press delete to remove the old transfer function. Enter the transfer function you want to plot. If you mess up, just erase the old equation reenter your equation/

    Figure 16

    18. Change the gain in the Margin Response equation to the process gain of your

    transfer function. Click on the equation and use the arrow keys to move the inverted L cursor to the gain. Use the backspace key to remove the old gain. Then type the new gain.

  • 19. Change the range of wavelengths. Recall the formula used to calculated is

    Edit this function by clicking on it and using the arrow keys to move the cursor to the parts of the equation you want to change.

    19, The atan2 function returns values between and . A plot of G(s) = 0.2 exp(-2s) is shown in figure 16. The breaks in this function are artifacts of the atan2 function. The actual function continues down without any breaks. You can either leave the program as it is and just remember that any breaks in phase angles are artifacts or you can use Mathcads programming feature to write your own function. The programming feature is described in other notes elsewhere. Some of my Bode plots use code to correctly plot phase angle.

    Figure 16