Real Time Data Acquisition and Display
21 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Walter Roberson
on 21 Apr 2014
Consider using timer() set to FixedRate, with the callback grabbing the data and updating the plot.
2 Comments
See Also
Categories
Find more on National Instruments Frame Grabbers in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!