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.
AI
for a National Instruments board. The installed adaptors and hardware IDs are found with daqhwinfo
.
AI
.
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.
duration = 1; %1 second acquisition set(AI,'SampleRate',10000) ActualRate = get(AI,'SampleRate'); set(AI,'SamplesPerTrigger',duration*ActualRate) set(AI,'TriggerType','Manual') blocksize = get(AI,'SamplesPerTrigger'); Fs = ActualRate;
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.
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.
plot(f,mag)
grid on ylabel('Magnitude (dB)') xlabel('Frequency (Hz)') title('Frequency Output by Function Generator')
![]()
This plot shows the nominal frequency around 1000 Hz. A simple way to find actual frequency is shown below.
![]() | Acquiring Data with a Sound Card | Evaluating the Analog Input Object Status | ![]() |