Real Time Data Acquisition and Display

21 views (last 30 days)
Gordie
Gordie on 21 Apr 2014
Commented: ak on 12 Feb 2021
I am currently attempting to acquire a voltage measurement from a national instrument daq device and display the the value in a plot along with a predefined value of a sine wave. I want to acquire and display the signal at 144Hz, but while I have been able to get the frequency up to 148Hz, but it is varying between 148Hz and 143Hz inside each signal acquisition period. An example of the code is listed below:
% create predefined sine function
t = 0:1/144:5;
x = sin(t);
% Create daq session
s = daq.createSession('ni');
s.addAnalogInputChannel('Dev1',0,'Voltage');
% Create scatter plot to update in loop
h(1) = scatter(0,0,'b+');
hold on;
h(2) = scatter(0,0,'bo');
% Assign a time delay that, along with processing time, sets frequency around 144 Hz
time_delay = 0.001;
i = 1;
% Start Clock
tic;
while t(i) < t(end)
% Create small pause
while toc<time_delay
end
% Scan for voltage
data(i) = s.inputSingleScan;
% Set data values from scan and sine wave
set(h(1),'XData',data(i))
set(h(2),'XData',x(i))
% refresh graph
drawnow
end
Please let me know if I was not clear about what I need, but I really appreciate any help anyone can provide. I have tried using is Continuous and fixed rate within the hardware, but the graph is only refreshed every 0.1 seconds, and I have not found a way to plot a second point into that graph.
Thank you for your help.

Answers (1)

Walter Roberson
Walter Roberson on 21 Apr 2014
Consider using timer() set to FixedRate, with the callback grabbing the data and updating the plot.
  2 Comments
Gordie
Gordie on 21 Apr 2014
I have tried the timer function calling inputSingleScan for each 7 milliseconds that go by. Unfortunately, it takes too long to call the function and perform the single scan (about 25 milliseconds). Would there be a way to acquire the data more quickly than inputSingleScan?
ak
ak on 12 Feb 2021
How to set sampling time if I know daq rate(scan/sec)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!