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
댓글 수: 1
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!