| Data Acquisition Toolbox | Search  Help Desk |
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 an 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
As described in "The Data Acquisition Session", using the Data Acquisition Toolbox to acquire data involves these steps:
Initialization: Create the analog input object AI for a National Instruments board. The installed adaptors and hardware ID's are found with daqhwinfo.
AI = analoginput('nidaq', 1);
Configuration: Add one channel to AI, 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 since it may be set to a value that differs from the specified value.
Execution: Startchans = addchannel(AI, 0);duration = 1; %1 second acquisitionset(AI, 'SampleRate', 10000);ActualRate = get(AI, 'SampleRate')set(AI, 'SamplesPerTrigger', duration*ActualRate);set(AI, 'TriggerType', 'Manual');% Create variables used for analysis blocksize = get(AI,'SamplesPerTrigger'); Fs = ActualRate;
AI, issue a manual trigger, and extract all data from the engine. Before start is issued, you should begin inputting data from the function generator into the data acquisition board.
Termination: Deletestart(AI)trigger(AI)data = getdata(AI);
AI.
delete(AI)
MATLAB Analysis
For this experiment, analysis consists of finding the frequency of the input signal and plotting the results. The signal frequency can be found withdaqdocfft.
[f, mag] = daqdocfft(data, Fs, blocksize);
data, and requires the values of SampleRate and SamplesPerTrigger as well as data as inputs. daqdocfft outputs the frequency and magnitude of data, which can then be plotted.
The results are plotted below.
This plot shows the nominal frequency around 500 Hz. A simple way to find actual frequency is shown below.plot(f, mag)grid on ylabel('Magnitude (dB)') xlabel('Frequency (Hz)') title(sprintf('daqdoc2\\_2\nFrequency Output by Function Generator'))
![]()
ymax = max(mag); find(mag==ymax)The answer is 994 Hz.