Data Acquisition Toolbox    

Acquiring Data with a Sound Card

Suppose you must verify that the fundamental (lowest) frequency of a tuning fork is 440 Hz. To perform this task, you will use a microphone and a sound card to collect sound level data. You will then perform a fast Fourier transform (FFT) on the acquired data to find the frequency components of the tuning fork. The setup for this task is shown below.

Configuring the Data Acquisition Session

For this example, you will acquire 1 second of sound level data on one sound card channel. Because the tuning fork vibrates at a nominal frequency of 440 Hz, you can configure the sound card to its lowest sampling rate of 8000 Hz. Even at this lowest rate, you should not experience any aliasing effects because the tuning fork will not have significant spectral content above 4000 Hz, which is the Nyquist frequency. After you set the tuning fork vibrating and place it near the microphone, you will trigger the acquisition one time using a manual trigger.

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

  1. Create a device object -- Create the analog input object AI for a sound card. 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 tuning fork into the sound card.
  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 example, analysis consists of finding the frequency components of the tuning fork and plotting the results. To do so, the function daqdocfft was created. This function 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. daqdocfft is shown below.

The results are given below.

The plot shows the fundamental frequency around 440 Hz and the first overtone around 880 Hz. A simple way to find actual fundamental frequency is

The answer is 441 Hz.


  Analog Input Examples Acquiring Data with a National Instruments Board