PH 415 Computer Interfacing
OSU logo
The content of this page is undergoing revision and will be moved to another site soon.
Task 3

Table of Contents

Choices: External or Internal Data Acquisition and Control Instrumentation?

  • Review the specifications of the AFG3021B and TDS1012B.
  • What combination of ADC precision and conversion rate is required? Eight bits at 1 GHz, 16 bits at 250 kHz or 24 bits at 7 Hz?
  • Review the specifications of the MAX 133. How can this be used?
  • Review the specifications of the NI M Series Multi-Function Data Acquisition Boards and the PCI-6221. Why was this board chosen? Reading the user manual is an absolute necessity for use of this board.
  • How do ADCs work?

Data Acquisition with PCI(e) Analog and Digital I/O Boards

  • Discuss communication schemes. Is direct communication possible? Usually, proprietary dynamic link libraries (dll or so) are required. Communication with the board through the dll requires knowledge of the data structures, classes and functions, information which should be available in a "C API" document. NI provides one global library, NI-DAQmx, for many boards. This is good and bad. It provides a consistent interface for many boards, but when you are using only one board this interface is more complicated than it needs to be.
  • Help with the C API is not available as a pdf but only through the help menu: programs > national instruments > NIDAQmx > C reference help. This was captured as a pdf by Daniel Gruss. This reference is incomplete, so communication with anything other than LabView will encounter unresolvable issues at some point. This is a result of the profitability of selling LabView. Other board makers provide a more complete C API and often modules for a variety of high-level programming languages such as Python and MatLab.
  • To find NI-DAQmx compatible devices, open LabView from the start menu, open a new project, go to the "Tools" menu and click on "Measurement and Automation Explorer". Go to "Devices and Interfaces" and under NI-DAQmx, "Dev1" should be present.
  • Can VISA be used? Not for the 6221 because there is no language, such as SCPI, to be communicated through the VISA protocols, so you must communicate directly through the dll. NI-VISA enables register-level communication with PCI (or PXI) DAQ cards which are bound to NI-DAQmx by treating them as PXI resources. To view what can be done with a PXI card with NI-VISA, select something similar to "PXI2::6::INSTR" that shows up under PXI System and press "Open VISA Test Panel". The accessible functionality should be evident.This Python/ctypes sample program can connect to a pci-6221 board but ends abruptly when, sadly, there is nothing to be said by either party.
  • It is useful to glean information about the functions and data structures of the dll by scanning it. First, locate the dll. Execute the DLL Export Viewer found in dllexp.zip. Also execute dependency walker found in depends22_x86.zip.
  • The discerning eye might notice that in nicaiu.dll and the programming API every constant and function has the "DAQmx_" or "DAQmx" prefix. The purpose of this was to drive programmers insane. NI's own programmers were probably written off as collateral DAQmx_damage. Fortunately, it was easy to create a class of constants and a class of functions for which this prefix has been removed. These classes are defined in nidaqmx_constants.py and nidaqmx_functions.py, and these modules were created by make_constants.py and make_functions.py which parse the include file NIDAQmx.h. Marina has a pci-6221 tab, and it is a DAQmx_-free environment. Those with significant experience with nicaiu.dll might ask "Why DAQmx_would this DAQmx_be of any DAQmx_value?", but we will just DAQmxhumor(them).

Using the Ctypes Module of Python To Access NI-DAQmx

  • Python provides a module called ctypes which enables your program to access the data structures and functions of libraries created using C and C++.
  • Use find_devices.py to find NI-DAQmx-compatible boards present in your computer. The result should be "Dev1".
  • To read a single analog input channel, download ain_nidaqmx.py which uses the module nidaqmx.py. Together, they constitute a modified version of the cookbook article. Reading the C API reference was necessary too. These modules use the DAQmx_whatever convention for constants and functions.
  • Set the function generator to produce a 2 Vpp sinewave at 1000 Hz and set the expected load impedance to high Z. Run ain_nidaqmx.py with the default values of samples = 2000, sample_rate = 100000. Zoom in on the plot and observe the density of data points. Save the data file with a suitably obscure name.
  • Does your data have any offset? Note that line 37 of ain_nidaqmx.py is set to default. Change "self.Cfg_Default" to "self.RSE" to remove the offset problem and use any AI GND pin.
  • Increase the amplitude of the signal to 5 V and examine the peaks of the graph for evidence of ADC saturation. Now increase Vpp slowly until evidence of saturation appears. You might want to refer to the specification document to see just how large Vpp can be. Fortunately, the function generator max Vpp is 20 V. Note the min and max values in the program. Lower the AD conversion range to -5 to 5. and set the function generator Vpp to 11 V and beyond, as directed by the instructor.
  • Set the ADC min max range to -10 to 10 V and experiment with digitization noise by observing the waveforms as you lower Vpp.
  • Explore the effects of sampling each cycle of the waveform at fewer and fewer points. At what sampling rate relative to the frequency does the waveform become seriously distorted? Save some interesting plots and data sets.
  • Determine the maximum sampling rate of the 6221.
  • Note that the program assumes that the data values are taken at a constant time interval. This might not be the case. It would be better to have the board report the time at which each data point was taken.

Fast Fourier Transform and Power Spectrum of a Digitized Signal

  • Begin by connecting the sine wave output of the function generator to both the scope and the pci-6221 card, henceforth referred to as the adc. The scope can sample at a rate as high as 1 Gsps, while the adc runs up to 240 ksps. The scope always produces 2500 data points per scan, while the adc has no limit. These are important differences, and there are situations for which one or the other instrument provides superior data. In the work below, compare the data from the scope to that of the adc. In particular, notice minimum and maximum frequencies that appear in the power spectra. Use either the newest Marina™ supplied on a task page for data acquisition or your own version, if it is sufficiently functional.
  • Set the AFG3021B to produce a 10 Vpp sine wave at 10 kHz with 0 offset into a high impedance, and acquire data from the adc at 105 sps for 104 samples. Note the peak power of the the fundamental signal and any harmonics. Also, note the maximum frequency produces by the fft algorithm. Expand the graph around the peak at 10 kHz. What is the peak frequency? What is the bandwith determined by the positions of the data points to either side of the peak? Now, vary the samples parameters to 1000 and 100. Make the same observation and report the differences. Draw a conclusion concerning the resolution and precision of the lineshapes as the number of data points decreases. Also, state a conclusion concerning the ability to detect harmonics as the number of data points decreases. Finally, how does the high frequency limit of the fft quantitatively depend upon the number of samples?
  • Set the FG to produce a 10 kHz square wave, 10 Vpp, 105 sps and 104 samples. Explain the observed the power spectrum.

Nyquist Frequency or Sampling Rate

  • Set the FG to produce a 10 kHz, 10 Vpp sine wave that is amplitude-modulated (AM) at 9 kHz to a depth of 50%. This produces sidebands at 1 and 19 kHz. Run the program with samples = 104 and sampling rate = 100kHz. Explain the positions and sizes of all peaks in the spectrum. Reduce the sampling rate through the sequence 100 kHz, 50 kHz, 40 kHz, 38 kHz, 37 kHz, 36 kHz and 30 kHz. Explain your observations. When the rate is 30 kHz, note that the 19 kHz peak appears as a peak at a lower frequency, leading to the statement that the 19 kHz peak appears as an alias at a lower frequency. Explain how this is possible using a mathematical or graphical argument. The Nyquist sampling rate is defined as the minimum sampling rate required to reproduce a sine wave at a particular frequency, that is, twice the signal frequency. Conversely, the Nyquist frequency is the highest frequency that can be reproduced at a particular sampling rate, that is, one half the sampling rate..
  • Set the sample rate to 25 ksps and samples to 104. Note that the 19 kHz sideband now appears at 6 kHz. Record the power ratios of both sidebands relative to the power at 10 kHz. Try to reduce the 6 kHz signal by at least 3 dB by inserting a low-pass RC filter.
  • Remove the RC filter and step the sample rate down through the sequence 23, 22, 21, 20.1, 20, 19.5, 19.1 and 19 ksps. Note the position and magnitude of the alias signal. Then continue, trying 18.9 and 17 ksps. State a conclusion concerning the efficacy of sub-Nyquist sampling.
  • At 17 ksps, insert the low-pass filter once again and measure the change in the power ratios among the peaks.
  • Explore the concept of sub-Nyquist sampling, that is, sampling well below the Nyquist sampling rate for a signal of a certain frequency. Set the FG to deliver a pure sine wave at 10 Vpp and use a sampling rate of 100 kHz. Calculate a set of frequencies beyond the Nyquist frequency for this sampling rate (50 kHz) which will appear with an alias of 10 kHz. Sequentially set the FG to these frequencies and measure the power on the power spectrum at 10 kHz. Here are examples of the power spectra from the scope and the adc when the applied frequency is 2.19 MHz. Notice that the signals are comparable even though the adc is sampling only once every 10 cycles. Such a low sampling rate works in this case because the coherence time of the input signal is much longer than the observation time. If time-dependent random phase is introduced, the sub-Nyquist sampling would not be as effective. Draw a conclusion about the usefulness of sub-Nyquist sampling.
  • The concepts of the Nyquist frequency and aliasing have a firm mathematical basis in the Nyquist-Shannon sampling theorem. Read about Claude Shannon, whose signature work is The Mathematical Theory of Communication .

Coherence of signals and Autocorrelation

  • Participate in the discussion of coherence of electronic signals
  • Use the Correlate() function of ain_nidaqmx.py or the autocorrelate button on Marina™ to observe the autocorrelation function of a sine wave from the AFG3021B. Begin with ν = 10 kHz, sample rate = 240000, samples = 1000 and about 2 Vpp. Vary the sample rate and the number of samples, and record the autocorrelation graphs. Explain why the graph always has the same shape. Is there a drift in the relative coherence of the function generator and the pci-6221 data acquisition board, or is there another explanation?
  • Delve deeper into the concept of coherence by setting the waveform generator to sweep the sinewave frequency from 10 kHz to 13 kHz in 10 ms. Using Marina™, view the signal in the time and frequency domains as well as observing the autocorrelation function. Be sure to take a sufficient number of data points. Then, gradually increase the final frequency up to a maximum of 100 kHz. Explain the rapid decay of the autocorrelation function and the recurrences of coherence.

Synchronous Detection

  • Synchronous or lock-in detection provides the ability to detect a small coherent signal amidst wide-band random noise or other coherent signals at different frequencies.
  • To achieve coherent or synchronous detection, a fixed phase relationship must be established between the DAC board and the function generator. Look at the 6221 data sheet and the C help reference to determine how to initiate data acquisition using the TTL output of the FG as a digital trigger input to the 6221.
  • Set up two function generators as described by the instructor and run both ain_nidaqmx.py and ain_nidaqmx_synchronous.py.
  • Determine the limits of detectability for interfering noise and an interfering single frequency.