Real Time Data Acquisition and Display

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.

답변 (1개)

Walter Roberson
Walter Roberson 2014년 4월 21일

0 개 추천

Consider using timer() set to FixedRate, with the callback grabbing the data and updating the plot.

댓글 수: 2

Gordie
Gordie 2014년 4월 21일
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 2021년 2월 12일
How to set sampling time if I know daq rate(scan/sec)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Acquisition Toolbox Supported Hardware에 대해 자세히 알아보기

질문:

2014년 4월 21일

댓글:

ak
2021년 2월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by