Data Acquisition Toolbox    

Acquiring Data with a National Instruments Board

Suppose you must verify that the nominal frequency of a sine wave generated by a function generator is 1.00 kHz. To perform this task, you will input the function generator signal into a National Instruments board. You will then perform a fast Fourier transform (FFT) on the acquired data to find the nominal frequency of the generated sine wave. The setup for this task is shown below.

Configuring the Data Acquisition Session

For this example, you will acquire 1 second of data on one input channel. The board is set to a sampling rate of 10 kHz, which is well above the frequency of interest. After you connect the input signal to the board, you will trigger the acquisition one time using a manual trigger.

You can run this example by typing daqdoc4_2 at the MATLAB command line.

  1. Create a device object -- Create the analog input object AI for a National Instruments board. The installed adaptors and hardware IDs are found with daqhwinfo.
  2. Add channels -- Add one channel to AI.
  3. Configure property values -- Assign values to the basic setup properties, and create the variables blocksize and Fs, which are used for subsequent analysis. The actual sampling rate is retrieved because it might be set by the engine to a value that differs from the specified value.
  4. Acquire data -- Start AI, issue a manual trigger, and extract all data from the engine. Before trigger is issued, you should begin inputting data from the function generator into the data acquisition board.
  5. Clean up -- When you no longer need AI, you should remove it from memory and from the MATLAB workspace.

Analyzing the Data

For this experiment, analysis consists of finding the frequency of the input signal and plotting the results. You can find the signal frequency with daqdocfft.

This function, which is shown in Analyzing the Data, calculates the FFT of data, and requires the values of SampleRate and SamplesPerTrigger as well as data as inputs. daqdocfft outputs the frequency and magnitude of data, which you can then plot.

The results are given below.

This plot shows the nominal frequency around 1000 Hz. A simple way to find actual frequency is shown below.

The answer is 994 Hz.


  Acquiring Data with a Sound Card Evaluating the Analog Input Object Status