Frequency Response Testing with Labview 5.0, the HP 3325B Function Generator, and the HP 3478 Multimeterby Monica Stewart |
Introduction to fs.viI wrote fs.vi (frequency sweep virtual instrument) mostly to get myself used to programming in G, the Labview visual language. I also wanted to familiarize myself with test equipment more advanced than the basic waveform generators, oscilloscopes, and DMMs on the majority of the schools test benches. Ideally, I produced a polished piece of Labview software that performs useful electronics tests in a manner more efficient than non-computer aided testing. In the end, my work was not as polished as I hoped, and there are several features I wanted to implement but did not due to lack of time, and sometimes due to lack of understanding. What I have produced is however, useful. It can make simple Bode plots of circuits in a few seconds to a few minutes.
The basic concept of how fs.vi works is pretty simple. A digital multimeter (DMM), function generator, and oscilloscope are connected via something called the General Purpose Interface Bus (GPIB) to a computer with Labview. fs.vi runs in Labview and allows the user to specify the a range of frequencies for the function generator to increment through. The number of increments may also be specified. While the function generator is doing this, the DMM or oscilloscope can be read by fs.vi and its peak-to-peak output can be noted. This collects enough data to create a Bode plot of whatever device is hooked up to these instruments.
fs.vi has a fairly intuitive front panel. All the user input is on the right in the dark frame. The tools and controls in the separate windows on the far right are rarely needed for the user, and can cause confusion. If you are planning to use fs.vi, but not do any programming or rearranging of the interface, keep the tools palette set to the hand symbol, and the small windows closed. |

|
Start Freq is the frequency the user wants at the low end of the Bode plot. In the image above this is set for 100Hz. End Freq is the frequency the user wants at the high end of the Bode plot. In the image above the Bode plot will end at 1Mhz. # of readings establishes the number of data points used to make the Bode plot. In the example there will be 20 data points used to form the Bode plot. Amplitude Vpp allows the user to control the peak-to-peak amplitude for the input signal. In panel above a signal of 1Vpp will the input signal to the test circuit. The input signal is always a sine wave. lin/log sweep would be set to log for most Bode plots. Since frequency response is usually thought of in terms of decibels/decade or decibels/octave, distributing our data reading logarithmically is logical. The exception to this is during very narrow frequency sweeps. In example the control is set for a log sweep. Data logging can be set to on or off. If on the program will record the data in text form and later prompt you for a file name and path for saving the data. You can then open the data with other software such as Excel. In this case data logging is off. DMM/Oscilloscope allows the user a choice between using an oscilloscope or DMM to read the output of the circuit being tested. In the above example the oscilloscope would be used to measure the test circuits output. x10 x1 is only relevant if the oscilloscope option is used. This should match the probe setting. The example above is set properly for an oscilloscope with its probe set at x1. Set to x1 when using the DMM or your readings will be off by -20dB. Below the frame of controls is an area for writing notes. This can be useful to make printouts understandable at a later time. Testing a simple filter
|

|
Lets use fs.vi in a simple example of a frequency dependent circuit, the simple low pass filter. As a starter lets use the following settings. start freq: 100 Hz end freq: 10 kHz # of readings: 20 amplitude Vpp: 4 Lin/log sweep: log Data logging: no DMM/Oscilloscope: DMM X10 x1: x1 Since our -3db point is 1600 Hz, will be scanning over a relevant range of frequencies. 4Vpp shouldnt damage any of the components, but it should be a plenty strong signal for the DMM to measure. 10 kHz is well within the bandwidth of the HP 3478 DMM. Hook up the frequency generator to the circuit and set up the DMMs probes to measure the voltage across the capacitor. The right arrow icon at the top of the front panel will start the test. The results should end up something like this: |

|
The maximum amplitude of almost 0 dB makes sense at the low end of the sweep. The high end of the sweep is responsible for the -35.19 dB attenuation. The graph marks the high and low amplifications with blue lines. The white line is -3dB from the maximum amplification. The Bode plot itself looks as expected. The graph below the Bode plot shows the slope of the Bode plot and makes it easy to see that we have an approximate 20dB/decade falloff as would be expected. The 1260Hz reading for the -3dB point seems a little low. This could be due to using a cheap capacitor, but it may be due to interpolation errors. The interpolation between points is simply linear. We could increase the number of samples, but that would make the test longer. Narrowing the range of frequencies swept might be a better strategy for finding a more accurate -3dB point. Sweeping from 500Hz to 2000Hz seems reasonable. |

|
Sure enough the new calculated 3dB point, 1470Hz, is a little closer to the expected value, and is no doubt somewhat more accurate. Lets narrow down even more, say 1000Hz to 1500Hz and lets say we go a little crazy and make the test for 50 data points. |

Notice that the test is a lot slower. We end up with a calculated 3dB point at 1500Hz. Our graph looks really funny now however. Right clicking on the graph, choosing X Scale and then Formatting will lead to a dialog box with a linear or log scale option. Choosing linear seems to only make things worse, but with some more adjustment, things will look better. Double clicking on the final number on the frequency axis will allow you to change the scale to end at 1500Hz. Now the graph starts to look more reasonable. |

| The plot of the low pass filter looking better with a little formatting. Notice that the bottom graph needs to be formatted separately. |
|
This is an example of a frequency sweep that could have been done linearly. A linear sweep would have evenly spaced the sample points, so in this example the points would be separated by 100Hz increments instead of the uneven spacing of the log sweep that scrunches the data points toward the low end.
Now lets get a little weird. Lets do our sweep from 100Hz to 2Mhz. To save time lets go back to just having 20 samples. Here are my odd results. |

|
The Bode plot looks somewhat strange with its steepening slope starting around 300kHz. Looking at the derivative of the curve below its clear that something significant is happening. The downward slope is going from a nice and normal 20dB/decade to over 80dB/decade. Is this due to non-ideal components? Is this due to the effect of the breadboard? Are the instruments flawed?
The breadboard and components do probably have significant non-ideal responses, but not enough to cause this. The instruments are not flawed, however we are not using one of them correctly in this situation. The DMM is designed with a 300kHz bandwidth. We are seeing the results of pushing the DMM beyond it limits as an accurate measurement device. While the DMM cannot be reliably used above 300kHz, the Gould 4072 oscilloscope has a bandwidth of 100MHz. Now lets leave the frequency sweep settings the same, but setup for an oscilloscope with a x1 probe. It would be a good idea to increase the input signal to 10Vpp for less noisy reading. Before you actually used the oscilloscope option, a word of warning. Using the scope is much slower than using the DMM. Its so slow in fact, that especially on the first use of the oscilloscope option, it will look like nothing is happening. Wait for at least 30sec before assuming something is locked up. If you are sure nothing is happening even though the program is running, it is much more likely that the Gould has locked up than the computer. Yes, you can "crash" the scope. I havent actually figured out what is causing this on occasion except that interrupting a sweep by pressing the stop button on the front panel will, more often than not, cause a scope lockup. Actually, a better description of the situation would be a "GPIB lockout". The scope will appear to work just fine, but GPIB commands will not be read, or a least, not read correctly. The fix is just like with a computer -- power-cycle the machine.
Assuming everything went well, fs.vi using the scope should produce a graph something like this. |

|
In this example, and this is typical, there is still some weirdness going on. In truth, however, things are not so bad. Everything looks great up to a little below 200kHz and there seems to be a spurious reading. Finally at the end of the sweep there is another strange data point.
To put this into perspective, lets look at this. |

|
This is an example of data being read in with everything normal except the signal generator was left disconnected from the circuit. This basically tells you that everything below 45dB is very suspect data drowning in noise. A logical solution to this would be to filter out signals outside the test frequency. This can be done in Labview, but I have not implemented this. The high-pass filter
Now lets switch around our simple low-pass filter to make a high-pass filter. |

|
Running our previous sweep on this somewhat new circuit gives us something most would have expected. |

|
This looks like a nicely behaving high-pass filter. Doing the same test with the DMM instead of the scope gives us this. |

|
The bandwidth limitation of the DMM is very striking in these situations. In the low-pass filter the signal was so weak at high frequencies that a little error added to the signal was not terribly noticeable. The scope is however slow to use, and noise might be a problem. Even the scope as setup up with Labview now is only reliable to about 3Mhz. This has to do with the sampling rate of the Gould scope. The limited sampling rate of the Gould scope will be discussed later.
A band-pass filter
Shown below we have a less predictable circuit. This is a band-pass filter made from following instructions in the ARRL Handbook, but fudging some to use standard and available components. I tried to make one of the lowest frequency band-pass filters they had tables for, and adjusted the component values to make the pass frequencies even lower. Adjustments can be made to make this a much lower filter, though this filter works well for demonstrations purposes because it pushes the bandwidth limits of some the tools used |

| A band-pass filter. Note that the 50 ohm resistor is for impedance matching purposes. The input has a similar impedance which is matched by the frequency generators 50 ohm output impedance. |
|
To get an idea of what sort of filtering pattern to expect, PSPICE simulations can give at least an approximation of the circuits real world behavior. Its not a simple curve. |

| Simulated Bode plot of the band pass filter. Click image for a larger version of the chart. |
|
Testing with the DMM revealed this response curve. |

|
Notice in the full panel view that the Q reading is now actually giving real results. Though it doesnt look exactly like the simulated test, the response is overall about right. Things look good, but the lower curve shows that the high end falloff is really steep. The filter should be roughly symmetric, rising and falling at about 100dB/decade. Instead of this, we have a 100dB/decade rise, but a -200dB/decade drop-off. Of course what is happening is that the DMM is not reading the high frequency signals accurately. As a matter of fact, at about 1Mhz the DMM is virtually blind to signals. Doing the same experiment with the readings made by the scope gives us a distinctly different set of curves. |

Reading the frequency response of the band-pass filter with the oscilloscope instead of the DMM. Click on the image for a full view of the panel. |
|
The little peak at 2kHz is probably noise. The filter is a little more symmetric now, rising and falling at about 50dB/decade, but now there is an annoying upturn at the tail end of the curve. Using the same number of samples, but on a narrower range of frequencies might give us more relevant data. |

|
Strangely there really does seem to be an upturn at the high end of the sweep. One might suspect this odd effect is due to capacitance in the breadboard itself. To test this I set up a high-pass filter with a 10k ohm resistor and one gap in a breadboard as a cap. Yes, thats correct, we are using two adjacent, but non-touching connections on the breadboard as a capacitor. This is the frequency response I read. |

| Making a high-pass filter with a resistor and adjacent internal conductors in a breadboard. |
|
The result is quit telling. There is the hint of a single pole 20dB/decade rise with a critical frequency at about 150kHz. This suggests that the breadboard can be thought of as lots of 106pf capacitors in series with 400k resistors. The 106pf capacitor would give the frequency response shown. The 400k resistor would give the -32dB maximum amplification. Things are not so bad since these stray capacitors are set up in series and therefore tend to disperse their effects. The curve levels at about 32dB which is pretty small, but almost exactly the value when we see an upturn in the end of the band-pass filters Bode plot. In short, the odd high-end response seen by the scope with the band-pass filter is almost certainly the result of stray capacitance in the breadboard.
An Active High-Pass Butterworth FilterActive filters can give good results without some of the bulk, number of parts, and fussiness of inductor using passive filters. A classic is the Sallen-Key filter, which is basically a two pole network of capacitors and resistors attached to an op-amp. |

| The simulated frequency response of the 741 based Sallen-Key filter designed for a critical frequency of 10kHz. |
|
This example is designed to give a high-pass response with a critical frequency of 10kHz.The op-amp is the basic 741. Simulation shows a basic two pole response with the bandwidth limits of the op-amp appearing between 500kHz and 1Mhz. Here is an actual fs.vi plot of the circuits frequency response. |

|
Notice the settings used. There was little sense in using a really strong signal which may actually make the readings look non-ideal because clipping and slew-rate limiting would limit the output. The frequencies are within the DMMs bandwidth, so there is little sense in using the oscilloscope to make the output readings. The results are very close to what was predicted by design and simulation.
Lets look at the response of this circuit over a greater range of frequencies, up to 2Mhz. To avoid the bandwidth limit of the DMM, we should use the oscilloscope. |

| A broad frequency sweep of the Sallen-Key filter showing the limitations of the 741 op-amp |
|
Since this is using the oscilloscope, the readings are noisy, hence the spike near 200Hz. What is curious, is the drop-off. There is a critical frequency near 200kHz. Is this due to the bandwidth of the op amp? The 741, used in this example, is rated with a bandwidth of 0.5Mhz. Maybe the problem is with slew-rate limiting. If this is the case, the 741 just isnt able to change is outputs fast enough to keep up with the input. If this is the case, lowering the input voltage should increase the high frequency response. Cutting down the input amplitude to 100mVpp does indeed reveal a small, but definite increase in high frequency response. |

|
Now the bandwidth extends beyond the 400kHz range, and is probably very close the limits of the op amps bandwidth. Notice that the effects of noise show up more since we are trying to see a small signal.
Let's go ahead and figure when slew rate limiting would become a problem. |
The 741 is rated to a slew rate of 0.5V/uS If Vout = Asin(wt) => dVout/dt = Acos(wt) => max(dVout/dt) = A(wt) = A(2*pi*f) If slewrate(sr) = 0/5V/us and A = .5V => f = .5V/us/(2*pi*A) = 160kHz Similarly if A = .1V, f = 800kHz which is greater than the bandwidth of the 741. This seems to match the results well.
More Oscilloscope ProblemsInteresting things can come from testing about the most simple circuit imaginable consisting on just one resistor. I did these experiments with a 10k resistor since I didn't want to load the 50ohm output impedance of the frequency generator. Ideally we should see a gain of zero across the entire frequency spectrum. We already know that this is not the case with the DMM with it's limited bandwidth of about 300kHz. What is more interesting is looking at the behavior of the more complex and difficult to use oscilloscope. Here is what you can expect from the very broad frequency sweep on a simple resistor using the scope for output readings. |

|
This is a little unnerving, but we must face facts. The oscilloscope will not be perfectly accurate in its measurements when used with fs.vi. Actually, the <1.5dB error in the sub 2Mhz region really isn't that bad for many purposes. I haven't been able to track down the source of this error which is equivalent a 10-15% error in voltage measurements. There is however a little place in the code that allows a user who really wants to zero out this error to some extent, to make a small adjustment to data coming back from the oscilloscope. Look for the numerical constant call "fudge factor". Typically a setting of about 1.15 corrects this fairly closely. This is very much a last minute tweak. Probably a better system would be to program fs.vi to use one channel to read the input, and another channel to read the output. This would slow the test, but it would compensate for any errors if the error is about the same in both the channels.
Somewhere between 2Mhz and 5Mhz something really goes wrong. We know that a resistor even with parasitics should not be actually amplifying a signal. To understand what is going on with this error, it helps to look at a sub-VI of the system. A VI is Labview-talk for a program, or "virtual instruments". VI's can be used in other VI's like subroutines, and hence become "sub-vi's". Go to the Windows menu while infs.vi's front panel and choose Show Hierarchy. Once the chart is shown, double click on the Gould 4072 icon, and you will see another front panel. In this panel, set the GPIB address to whatever the address of the scope. In my case it is 24. Set the frequency generator so it is providing a strong signal to the oscilloscope (say 1Vpp) with a frequency that is not too high, say 100kHz. Click run and you should get a nice copy of the waveform on the computer screen. By the way, this VI is good for making printouts of waveforms from the scope. |

|
Now try the same thing, but with the frequency generator set at 10Mhz. Now you will probably not get a cute sine wave, but instead you will bet an odd pattern like this: |

|
What seems to be happening is that there are not enough samples of these fast waveforms for this program to make its graph smooth, and instead of nicely interpolating the gaps between data points, it's assuming the value is zero. Due to the way the data is captured, the DC component is not necessarily removed. These false zeros can become false low points on the curves, and make the peak-to-peak calculations larger than reality. Hence we have the false reading suggesting an amplifying resistor. This sub-vi was not originally written by me, and I don't completely understand how it works, but I found that adding a long delay while data is being gathered allows time for the data to accumulate enough to make good waveforms. This also makes reading waveforms slow. When I first began working with this program, artifacts were cropping up with frequencies of only a few hundred kHz. A ten second data gathering delay seems to have allowed me to increase effective bandwidth of this system up to about 3Mhz. For those who wish to work on improving fs.vi, improving gould4072 might be the most effective approach.
LeftoversThere are a couple of items connected to the GPIB bus which are not being used.The HP 5384 Frequency Counter was part of my original fs.vi system. I had the idea of using the frequency sweep option of the frequency generator. It is possible to set up the 3325B to sweep frequencies for a preset range of frequencies over a given amount of time, and it will even do it logarithmically or linearly. I thought this would make a great way to avoid lots of GPIB I/O by simply sending one line of commands to have the frequency generator begin a sweep, and at the same time the output from the circuit under study could be gathered. There was one problem, how would fs.vi know what frequency was being tested at a given instant? The answer seemed straightforward enough to me. Hook up the frequency counter to read the input frequency in real time. In fact, what seemed simple was somewhat awkward. First of all, this entailed yet another set of wires to be connected to the circuit in question. This is not such a big deal, but it did make things more cluttered. Secondly, the frequency counter can become confused by stray frequencies especially if you are using small input frequencies. Thirdly, and most importantly, the frequency counter is too slow. It takes at least .1s for the counter to lock in on a good count. By the time the GPIB bus has sent a request for a reading from the counter, and receives and answers, the frequency has changed. With very careful design with considerations to timing, this system could probably work over a limited bandwidth, but there seems to be little advantage to forcing this system to work. The HP 6622A power supply was something I really wanted to get working, but I have yet to actually get the GPIB to work with the machine properly. This is not the machines fault. I'm pretty sure the machine works at present. Manual controls work fine, though I think there needs to be some more wiring in back for proper operation of the second supply. The machine does seem to respond to the GPIB. Though I have never been able to make the machine do what I want it to do from Labview, I have made the "RMT" (remote operation) arrow turn on the power supply's display by sending commands from Labview. I really wanted to get the power supply under the control of the bus because then the behavior of things like op-amps could be tested under various power supply conditions. It would be interesting, for instance, to see how a 741 behaves with various supply voltages. What happens to it's slew rate under low voltages? These questions could be answered with manual operation, but automating a system could make testing a breeze.
Even more interesting might be making a transistor curve tester with Labview and the power supply. The supply can provide a given voltage or current, so making a curve tracer should be easy once someone figures out how to control the device remotely.
How the program works
While you are looking at the front panel, pressing ctrl-e will show the back panel which is the visual equivalent of the source code for the front panel. The back panel of fs.vi might seem a little intimidating at first. I will try to break down the program into broad groups so some overall organization can be understood. Before messing around with this complicated a program, you may wish to try the tutorials provided by National Instruments and available at NSCC. |

|
This section handles the inputs from the user for the start and stop frequencies, the number of data points requested, and whether or not a linear or log sweep is needed. The start and stop frequencies are a little more complicated than the other entries because different units, "Hz","KHz", and "KHz", need to be handled. |

|
This whole section is within a for/next loop. This is where the code iterates through each frequency and its corresponding readings from the DMM or oscilloscope. The nested sequence and case structure in the upper left are for reading the DMM or oscilloscope. The fudge factor is mentioned earlier in this report, and might be the first item in the code a user changes because it's used to calibrate the oscilloscope readings. The section in the upper right is actually very simple. It allows the for/next loop to output each frequency and the corresponding readings from the DMM or oscilloscope. This data is converted to decibels in this section as well. The bottom right is taken up with what looks like an octopus, and a scary one at that, but what is happening is really fairly simple. This section gathers together lots of shorts strings (that's the octopus) and sends this data to the frequency generator to tell it exactly what to output.
This for/next loop outputs two arrays, one listing the frequencies tested, and the other the corresponding outputs in decibels. |

|
This is a confusing section. The top area is outputting the bottom graph of the front panel. The
The Bode plot is looks more complicated, but that is only because extra data is being added for the blue high and low amplification lines and the white -3dB line. Each of these extra lines get their own arrays. |

|
This shows an option not discussed much in this report. If you want the data that is usually just displayed in the graphs, saved as test files, there is the Data Logging option. This case structure allows this to happen. |

|
This section is a little tricky to understand even though all it does is find the maximum amplitude, the minimum amplitude and the -3dB level. For those who want to alter this section, I recommend study of the |

|
This may be a little scary looking, but I think I can offer some help to understanding it. The first part of this section finds at what frequency the Bode plot breaks the -3dB point and falls below the -3dB. The output[0]=-10 output[1]=-8 output[2]=-6 output[3]=-4 output[4]=-2 the threshold vi would output 3.5. The second icon, the interpolation vi can take a non-integer index value, apply it to an array, and return an interpolated value corresponding to the non-integer index. Continuing our example, lets say the corresponding frequency array is: freq[0]=2000 freq[1]=3000 freq[2]=4000 freq[3]=5000 freq[4]=6000 Now the interpolation vi will return 5500 (assuming it was interpolating for the non-integer index of 3.5), which is the correct value of about where the frequency causes and output of -3dB. It's easy to assume that programming in Labview should be easy because it's so visual. Actually, I think some people who are used to text-based systems of programming will need to spend some time retraining their minds to new ways of imagining programs. Some information regarding fs.vi can be found here. This was made with the Labview documentation feature. I moved many of the sub-vi's to the fs folder.
Further Reading and Background
Ramakant A. Gayakwad. Op-Amps and Linear Integrated Circuits. Prentice Hall, Columbus, Ohio, 2000
John Fivnichy (N2DCH). Ladder Crystal Filters. MFJ Enterprises Inc., Starkville, MS, 1999 Any ARRL Handbook from the last thirty years should provide enough information for understanding references to the passive band-pass filter discussed.
Don't forget to check out the school's Labview manuals. Note that I used Labview 5.01 for all my work. I'm not sure if the newer Labview 6 is fully
compatible with fs.vi. |