Plotting real time data in matlab with Ni-daq, but view the entire graph as it is plotting

52 ビュー (過去 30 日間)
Hi :)
I have some problems with some matlab code.
I want to make the code in matlab which can display a live plot of the data that I collect with a measuring instrument from national instruments (Ni-daq 6009), the signal I need to collect an EMG signal, which then represented as a real-time plot matlab.
So far I have made the following code from examples from mathworks http://se.mathworks.com/help/daq/examples/acquire-continuous-and-background-data-using-ni-devices.html, but it is constantly updating the axes so that the plot does not appear in just one plot with fixed x and y axes, but constantly updating, so i can only view one second at a time . But I want to show the graph in a plot which has a fixed x and y axis (eg. X, 0500, y, -500,500) and from there the signal is displayed as a running line in the same plot.
The code I have so far:
s = daq.createSession('ni');
addAnalogInputChannel(s,'Dev2', 0, 'Voltage');
s.Rate = 5000;
s.DurationInSeconds = 10;
s.NotifyWhenDataAvailableExceeds = 1000;
s
lh = addlistener(s,'DataAvailable', @(src,event) plot(event.TimeStamps,
event.Data));
s.startBackground();
Hope someone can help, i would be very thankfull :)

採用された回答

Mike Garrity
Mike Garrity 2015 年 12 月 8 日
This page and this page in the doc are pretty good introductions to some of the techniques you need here. Basically what you're missing is a call to drawnow that tells MATLAB that you want to update the figure.
  1 件のコメント
Toby W
Toby W 2015 年 12 月 13 日
編集済み: Toby W 2018 年 11 月 8 日
Aha, i tried to plot some sine waves with drawnow. But i dont seem to be able to use drawnow with the code i tried to make. It doesnt seem to work. Sorry, but im pretty new to programming, can you give some hints on how to implement drawnow in the code? :)
Thank you :)

サインインしてコメントする。

その他の回答 (3 件)

Bill York
Bill York 2015 年 12 月 11 日
Mike is right. You need a call to drawnow in your listener. In this case you are asking for 5000 scans per second. That is faster than eye can observe so you'll want to limit the drawnow rate. Drawnow has an option called "limitrate" for this purpose.
If you call "drawnow limitrate" in your listener you'll get the plot updates.
You might also benefit from the "nocallbacks" option in this case. Try it out and let me know.
  1 件のコメント
Toby W
Toby W 2015 年 12 月 14 日
編集済み: Toby W 2015 年 12 月 14 日
Drawnow works but...
I have made the following code now, with drawnow:
devices = daq.getDevices
devices(1)
s.Rate = 5000
s = daq.createSession('ni');
addAnalogInputChannel(s,'Dev2', 0, 'Voltage');
data = s.inputSingleScan
s.DurationInSeconds = 10;
[data,time] = s.startForeground;
h = animatedline;
axis([0 10 -5 5])
xlabel('Tid (s)');
ylabel('Amplitude (V)');
x = time;
for k = 1:10000
y = data(k);
addpoints(h,x(k),y);
drawnow
end
This is working, but this is not updating live. It shows the data after it have been recorded, but i want to see the data plot in real time :)
I have tried to write s.startBackground() instead of s.startForeground, but that gives an error. Hope you can give me some good advice.
Thanks for your patiens :)

サインインしてコメントする。


Nauman Hafeez
Nauman Hafeez 2018 年 5 月 2 日
Hi everyone,
"This is working, but this is not updating live. It shows the data after it have been recorded, but i want to see the data plot in real time :)"
I would appreciate if anyone has any clue about it? Plotting live data as it is being recorded. Or is there any way I can use startBackground function when I am having an output channel in the session?
Thank you

sagoe gad
sagoe gad 2018 年 9 月 13 日
Add your h object to the for loop.
for k = 1:10000
y = data(k);
h=animatedline;
addpoints(h,x(k),y);
drawnow
end
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 9 月 15 日
The above should be
h=animatedline;
for k = 1:10000
y = data(k);
addpoints(h,x(k),y);
drawnow
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by