No BSD License  

Highlights from
DAQ Report

  • Readme.mThis examples shows how the Data Acquisition Toolbox can be used in
  • core_example.mThis example produces a signal at a fixed frequency through the sound card and
  • View all files

DAQ Report

by

 

Data Acquisition Toolbox used with Report Generator.

core_example.m
% This example produces a signal at a fixed frequency through the sound card and
% then acquires that signal back in through a National Instruments card.  The acquired
% data is then analyzed to determine the original signal frequency.  Notice that 
% not applying a window to the data causes the determined frequency to be inaccurate.

%    CP 2-25-98
%    Copyright (c) 1998-1999 by The MathWorks, Inc. All Rights Reserved.
%    Revision Date: 01/23/02
%    Please send comments or problems to support@mathworks.com.


close all
clear all

% Create the output
ao=analogoutput('winsound');
addchannel(ao,1);
ao.SampleRate=8000;
ao.RepeatOutput=inf;

% Create the data for the output
freq=50;
timeVec=(0:1/ao.SampleRate:1-1/ao.SampleRate)';
data=sin(2*pi*freq*timeVec);
putdata(ao,data);

% Set up Sample Rate and blockSize
Fs=ao.SampleRate;
blockSize=2048;

% Set up the input object
ai=analoginput('nidaq',1);
ai.InputType='singleended';
addchannel(ai,0);
ai.SampleRate=Fs;
ai.SamplesPerTrigger=blockSize;

start(ao);
start(ai);

[indat,time]=getdata(ai);

stop(ao)

winDat=indat;
% Uncomment the following line to apply a window to the data
%winDat=hanning(length(indat)).*indat;

xfft=abs(fft(winDat));
mag=20*log10(xfft);
mag=mag(1:end/2);
[ymax,maxindex]=max(mag);

subplot(2,1,1),
  xdat=1:Fs/blockSize:Fs/2;
  plot(xdat,mag)
  xlabel('Frequency (Hz)')
  ylabel('Magnitude (dB)')
  title(['Expected Frequency = ' num2str(freq) ...
         ' Hz, Analytical Frequency = ' num2str(ymax) ' Hz'])
  grid on

subplot(2,1,2),
  idx=1:blockSize/2;
  plot(time(idx),indat(idx,:));
  axis([0 time(idx(end)) min(indat(idx,:)) max(indat(idx,:))])
  xlabel('Time (seconds)')
  ylabel('Volts')
  title('Acquired Data')

Contact us