time lag in plotting and acquiring data with Instrumentation toolbox

조회 수: 2 (최근 30일)
jim private
jim private 2015년 9월 12일
편집: Walter Roberson 2015년 10월 1일
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

답변 (2개)

Walter Roberson
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
  댓글 수: 1
jim private
jim private 2015년 9월 13일
편집: Walter Roberson 2015년 10월 1일
hi walter.
thanks for the help.. I think your right, this is the right way to do it. However, I still cant make it work right. I want to have it both plot the data and also save the data to disk. What you are slowing will keep plotting it to disk. How does the data ever get saved to disk? I tried making a separate function called getAIdata.. really just hung up on this and need an example
Also would like to write the data to disk periodically in a while loop so it wont fill up memory. Any ideas on examples or how to do this?
daq.getDevices;
s = daq.createSession('ni');
s.Rate = 10000; %sample rate
s.DurationInSeconds = 1 %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
ai_data=[];
lh = addlistener(s,'DataAvailable', @plotData);
lh2 = s.addlistener('DataAvailable', @getaiData); %listener handle
for n = 1:1:duration
end
----- ----
function [ai_data]=getaiData(src,event)
global ai_data
ai_data=[ai_data;event.Data];
end

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


Vinod
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.

카테고리

Help CenterFile Exchange에서 Analog Data Acquisition에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by