5.1 Introduction Laboratory 5: ircuits and Filtering For this lab, you will be comparing the experimental behavior of a filter with analytical behavior modeled in MATLAB using Bode plots. During the lab period, you are going to build a circuit to analyze a first-order filter consisting of a resistor and a capacitor in series. You will then take eight sets of voltage readings for the output of the filter - each will be driven by a single frequency sinusoid, but the frequency will change. You will then compare their magnitude and phase ratios to those obtained by a transfer function. When finished with this lab, you will be able to perform experimental and theoretical analysis of basic filters. 5.2 In-Lab Assignment There are six main parts of this assignment that must be completed in the lab: (1) Logging into a DAQ machine and starting MATLAB (2) Starting a browser, then downloading and modifying the pre-written DAQ software (3) Building the circuit and wiring the measurements (4) Measuring responses to eight sine waves at different frequencies (5) Graphically comparing your results to analytical results from Maple (6) Transferring the data files to each member in the group (7) leaning up Once these parts are done, there will be several parts that may be completed outside of lab, including comparing the experimental results with the theory covered in class. Those sections will be done in groups of two (three if your lab group had to have three people). 5.2.1 Logging In For this week you will only need one person in your group to log in to the DAQ computer (identified by the gray cable coming out of the back and connected to the B-68LP card), as you will be using this machine for taking data from the circuit. Whoever is sitting at the DAQ machine can log in using their own credentials. You should then start MATLAB 2015b on the P. After MATLAB has finished starting, make sure the working directory is empty. 5.2.2 Downloading Files Once that is done, start the Firefox browser (if possible; Explorer if not) and point it to: http :// classes. pratt. duke. edu / FILES / EG224 / DAQS / filter There will be two files for you to download - right-click on the name of each and save the files (either Save Link As... or Save Target As...) to the :\Users\NetID\Documents\MATLAB directory where NetID is the NetID of the person who logged in. Lab 5 1
5.2.3 Building the ircuit and Wiring the Measurements The circuit for this week will simply be a voltage source in parallel with a series combination of a resistor and a capacitor. Each group will have a different combination, so make sure to write down the nominal resistor and capacitor values you have as well as which envelope it came from. Make sure they match the label on the envelope and the table on the Pundit page, too. The circuit diagram is as follows: v v S v and you will be measuring the source voltage v s (t), the resistor voltage v (t), and the capacitor voltage v (t). The network listing and a more detailed circuit drawing including the specific lines and pins to use are in Section 5.7 on page Lab 5 6. Use the small white breadboard to build the circuit. 5.2.4 Measuring esponses to Eight Sine Waves at Different Frequencies Assuming you are primarily interested in knowing the voltage across the capacitor, the differential equation that models the circuit can be found using Kirchhoff s Voltage Law, and is: dv dt + v = v s For this lab, you are going to focus on obtaining data points to create your own experimental Bode magnitude and phase plots for this filter. To do this, you will be running a program called FreqFunction. The FreqFunction program will use the loop s controlling variable k to determine which of eight different angular frequencies to use for the input voltage sinusoid. The program will wait for you to hit return, then take data for either 5.5 periods of that sinusoid or five time constants of the circuit, whichever is longer. The latter is to make sure all the transients have gone away and that you see the A steady state response. You will notice at higher frequencies that the program takes more than 5.5 periods of data and you should also notice an overall exponential offset that goes away over time. After each run is taken, you should qualitatively determine if the waveforms on the screen match what you think should be happening with your particular values. You will do this two different ways. Verification Using Lab 4 After you have taken data at the highest frequency (300 rad/s), you should use your Maple program from Lab 4 to see if your results match. This would be a good job for a partner not at the DAQ machine. Log into the P, then use MobaXterm to log into an OIT machine. Bring up the Maple worksheet for Lab 4 and then save it with a new name. You will simply need to change the forcing function (most likely in a variable called NewSourceVals) and the duration (in your plot command). The forcing function in the first run will be sin(300 t). You can hard-code the duration based on the duration of your MATLAB graph. Once you have the Maple sheet working for ω = 300 rad/s and it looks like your MATLAB graph for the same set of circumstances, have a TA come by to verify that the graphs match and are correct. Your group cannot get credit for this lab without getting checked in for this verification step. After the first run is done, you should keep modifying the Maple worksheet by changing the frequency and the plot duration, the re-running the worksheet to make sure your Maple results closely match your MATLAB data. You will not be turning in anything from Maple, but again, your group cannot get credit for this lab without getting checked in for this verification step. Verification Using Transfer Function The transfer function between the input voltage and the capacitor voltage, for example, is: H(jω) = V 1 (jω) V s (jω) = jω 1 jω + = 1 jω + 1 = 1 1 + j ω 1/ = 1 jω + 1 Lab 5 2
depending on how you want to represent the various parts of the transfer function. From the perspective of a straightline approximation to the Bode magnitude plot, the corner frequency for the denominator term is ω corner = 1 - at significantly lower frequencies, nearly all the voltage will drop across the capacitor. At exactly this frequency, the magnitude ratio should be 1/ 2 0.7071. As the frequency increases, the peak capacitor voltage should continue to decline relative to the peak input voltage. The program takes data for the highest frequencies first since those runs are faster and you can make sure you are taking good data. 5.2.5 Saving Data The program will automatically store your data in files called Data_FFFF_EE_IDS. mat where FFFF is the angular frequency of the input sinusoid, EE is the envelope number, and IDS is the ID string. The program does not save the plots - you will copy another file into your OIT account both to help you obtain the particular data from the graphs and to create a single figure with the graphs you need. Before continuing, make sure the graphs make sense. The voltages should all be sinusoids, for example. 5.2.6 Transferring Files Once you have taken the data for the eight single frequency forcing functions, you have completed the data acquisition part of this assignment. At this point, each person in the group will need to put all eight data files as well as the data acquisition script (FreqFunction) into their own accounts. Use the SSH Secure File Transfer program to do this for each person. For instructions on how to transfer files, go to the Pundit page on Transferring Files. Each of you will want to create a lab5 directory in your OIT space for the course, then put the files in there. Once the first person has transferred the files over, that person should close the transfer window and let the other members of the group repeat the above process for themselves. 5.2.7 leaning Up Once you are sure that each member of the group has a complete set of valid files, delete all the items from the P s MATLAB directory, then empty the Windows ecycling Bin. For your circuit: make sure you have written down your envelope number and the values of the resistor and capacitor within it, then put the capacitor and resistor back in the numbered envelope and detach all the wires from the breadboard and B-68LP. Have a TA come by to verify that your MATLAB directory and ecycling Bin are empty and that you have the proper parts inventory; then return all the circuit parts to the front of the room. Please be especially careful to make sure the correct capacitor and resistor go in the envelope and that the envelope goes back into its tray. This concludes the portion of the laboratory that must be completed in B209. 5.3 ollaboration Policy for This Assignment Please note - the rest of this work is a collaborative effort but must represent a collaboration. I forgot - what does collaboration mean? You are expected to work together on the programs that need to be written to produce your graphs, to work together on determining the answers to the various questions posed, and to work together on creating the final report. Be sure you know who your partners are and how to contact them, then set up a time early to get together and work on this assignment. Do not wait until the last minute and do not let yourself become the only person doing any work or the person doing no work. egardless of whose account is used to generate results and the report, a complete set of the final files (data, graphs, report, etc.) needs to exist in each person s account. Your group is certainly welcome - in fact, highly encouraged - to start the analysis portion of this assignment in B209. The following instructions are written assuming you are at a P in B209. Note that the lab5 directory should already exist, so the second command in step 3 should produce an error. Lab 5 3
5.4 Getting Started 1. Log into one of the Ps in the lab using your NET ID. 2. Start a browser and point it to http://pundit.pratt.duke.edu/wiki/lab:b209. heck out the Using the Ps to un Unix Programs emotely section for how to get connected and make sure the connection is working. 3. Once connected to a machine, switch into your EG 224 directory and create a lab5 directory inside it: cd EG224 mkdir lab5 4. Switch to your lab5 directory: cd lab5 5. Get the relevant tar file from Dr. G s web space: wget people.duke.edu/ mrg/eg224/lab5files.tar 6. Expand the files from the tar file: tar -kxvf lab5files.tar 5.5 Assignment The analysis portion consists primarily of comparing the theoretical magnitude ratios and phase shifts for the transfer function between the input voltage and the capacitor voltage to those obtained experimentally. 5.5.1 Frequency-Domain omparison For the analysis, you will be looking at the magnitude ratios and phase differences for pure sinusoids at different frequencies. To determine experimental data points for the frequency response of the circuit, you will need to examine the peak voltages of the capacitor and the total relative to one another. Note that the peak value for the source voltage should be 1 V in each case. First, use the applots code that was copied into your OIT account to look at the eight sinusoids. Follow the instructions to save your graph. Make sure that the relationship between the capacitor voltage and the total voltage makes sense as the frequency increases. Next, you will need to determine the magnitude ratios and phase shifts experimentally. To fill out the following data, you will plot the source and capacitor voltage as a function of time, zoom in to where you can see the last complete set of positive peaks for the voltages using the magnifying glass feature in MATLAB, then use the ginput command to pick points off the graph. To help, one of the scripts you copied into your OIT account - called GetPeaks - does much of this work for you. un the program and follow the directions it gives. The program will automatically save the voltage and time data - later, you will use the data to fill out the following table: ω v speak t speak v peak t peak = v peak v speak = 180 π ω(t speak t peak ) 1 2 5 12 25 60 130 300 Note that the frequencies have relatively even logarithmic spacing. The ratio between one value and the one after it is between 0.4 and 0.5. Also - be sure that you are taking point from the same period - the resistor and capacitor peaks should be no more than a quarter-period away from the total peak. Lab 5 4
Your group should now write a MATLAB script that loads the data saved by GetPeaks. This code should then calculate the magnitude ratio and phase angle based on the value and timing of the peaks you measured. Your phase angle should be reported in degrees - this will become important when you compare your experimental values with the analytical ones. Next, in the same script, you will be creating two figures - one for the magnitude information and one for the phases. In the first figure, create a semilogx plot of 20 log 10 (G) versus the forcing function frequencies - since you only have eight data points, plot them as black circles. Does this graph make any sense given that you are plotting the magnitude ratio of the capacitor voltage as a function of frequency? If not - figure out why not. If the plot seems to make sense so far, however, you may proceed to the next step. MATLAB can determine the magnitude ratio and phase shifts for a transfer function with a command called bode. The bode command takes a transfer function and a frequency range as inputs and produces the magnitudes and phases as outputs. MATLAB generates transfer functions in a variety of ways - one of the easiest being the tf command. The tf command expects two inputs - the coefficients of the numerator and the coefficients of the denominator of a transfer function. In this case, the transfer function would be: so the code to create the transfer function is: = XXX ; = XXX ; s = tf s ); H = 1 / s** + 1) H(jω) = V (jω) V s (jω) = 1 jω + 1 The letter s that is used by tf is the frequency-space representation for a Laplace transform. It serves the same purpose as jω. For the bode command, generate a logarithmically-spaced array of between 1000 frequencies that span the same domain as the experiment and grab the outputs. Give the transfer function and this array as inputs and grab the outputs. For whatever reason, the output from bode is a 1x1xN matrix for a single transfer function taken over N frequencies, so there is a bit of trickery involved generating variables you can plot. Specifically, you have to squeeze the data. That is: Omega = logspace log10 1), log10 3000), 1000); [HMag, HPhase, HOmega ] = bode H, Omega ); HMag = squeeze HMag ); HPhase = squeeze HPhase ); Note: the bode command calculates the phase angle in degrees. Now add a plot of the analytical magnitude ratios to the experimental graph created above - use a black line for this plot. Add a legend, labels, and a title. Finally, use the print command to save this plot. Next, follow a very similar procedure for plotting the experimental and theoretical phases (in degrees) on the same graph. In the lab report, you will include these two graphs as well as the code used to create them. You should also comment on how well or poorly the experimental data matches theory and any reasons you can think of for any discrepancies. Note that you do not need to include the text of the FreqFunction or apsplots codes. 5.6 Summary of Lab eport For the lab report, there will be a graph with all eight sinusoids from the FreqFunction run (made by the apsplots program), two Bode plots (one with the experimental and theoretical magnitudes and one with the experimental and theoretical phases), and a MATLAB script for performing and plotting the frequency-domain analysis. You will replicate the data table with the magnitude ratios and phase differences for the experiment. You will then use all the information at your disposal to answer the questions or respond to the comments in this assignment. There is a L A TEX skeleton for the lab report in the lab5 folder from which you copied files. While you are not explicitly required to use L A TEX, this skeleton will automatically bring in the MATLAB graphs and codes that you need as well as generate a table of contents and a list of figures. Even if you do not use the skeleton, you may want to use it as a point of reference for making sure you turn in all the parts of the lab. Lab 5 5
5.7 ircuit Diagrams and Network Listings Item First Second Note ES Pin F10 Pin F16 Your Value: kω AP Pin I16 Pin Y16 Your Value: µf ED1 Pin H10 Line L22 DA0OUT BLK1 Pin Y1 Line L55 AOGND BLK2 Pin Y5 Line L67 AIGND ED2 Pin I10 Line L33 AH1: vs GN1 Pin Y8 Line L66 AH9: vs ED3 Pin G10 Line L65 AH2: v GN2 Pin G16 Line L31 AH10: v ED4 Pin H16 Line L30 AH3: v GN3 Pin Y10 Line L63 AH11: v Table 5.1: Network Listing for ircuit Measurements AH2 v AH10 AH1 DA0OUT AH3 v S v AH9 AOGND, AIGND AH11 Figure 5.1: ircuit Diagram for ircuit Measurements Lab 5 6