time lag in plotting and acquiring data with Instrumentation toolbox
2 次查看(过去 30 天)
显示 更早的评论
I'm using the instrumentation toolbox to acquire data from a NI USB 6366. I want to periodically plot the output to screen so I can verify it is good. To do this, I have to stop the acquisition.. By the time I can plot the data and restart the session, there is data that is missed creating a discontinuity. Futher, I try to log the data to disk, it also misses a huge chunk of data.
Ive attached a screen shot of a 3Hz sinewave showing how it is hacked up by this process.
In NI labview, the data is logged continuously while it is displayed. I don't see anything in the demos on how to write a practical program with this toolbox, some help is really appreciated.
I need to keep the sampling rate at about 10k and record for a few minutes.. I dont necessarily need to log data to disk but want to atleast plot the data now and then.
program.
daq.getDevices;
s = daq.createSession('ni');
s.Rate = 10000; %sample rate
s.DurationInSeconds = .5 %time length of acquisition
duration = 300
display('acquiring data')
[ch, idx] = addAnalogInputChannel(s,'Dev1',[0, 1],'Voltage'); %addAnalogInputChannel(s,deviceID,channelID,measurementType)%turning on all 8 channels for now
data = []
divsor = 3;
figure,
for n = 1:1:duration
newdata = s.startForeground();
newdata(:,1) = 100*newdata(:, 1); %CURRENT PROBE 0.01 volts per amp*
newdata(:,2) = 1*newdata(:, 2); %
data = [data; newdata];
plot (data)
time = 1/s.Rate:1/s.Rate: s.DurationInSeconds;
plot(data)
xlim([0 divsor*size(newdata ,1)])
legend('Current', 'Volts')
if mod(n,divsor) == 0
display (['Seconds' , num2str(s.DurationInSeconds*n)]) %progress
dlmwrite (filename,data, '-append');
data = data(divsor*size(newdata,1): size(data,1), :);
end
end
0 个评论
回答(2 个)
Walter Roberson
2015-9-13
Instead of executing in the foreground, execute in the background after having created a DataAvailable listener;
lh = addlistener(session,'DataAvailable',callback);
You might want to alter the notification threshold; see http://www.mathworks.com/help/daq/ref/notifywhendataavailableexceeds.html
Vinod
2015-10-1
Take a look at this example
You can modify it to plot and write data to the disk. You won't be using the software defined triggers, but this should help you get started writing your code.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Analog Data Acquisition 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!