フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Sampling using two systems: NI Data Acqusition combined with MexFunction Loop

1 回表示 (過去 30 日間)
Eddy H
Eddy H 2016 年 4 月 22 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi,
I am using matlab to sample data from a system connected through a NI card. The data is stored in a global variable called datastore. I am also sampling from a USB connected device using a mexfunction at a different sample rate using a loop - see code below.
Main code (abbreviated):
global datastore
datastore = [];
s = daq.createSession('ni');
s.DurationInSeconds = Trial_Time;
s.Rate = 1000;
ch_0 = addAnalogInputChannel(s,'Dev1','ai0','Voltage');
ch_1 = addAnalogInputChannel(s,'Dev1','ai3','Voltage');
lh = addlistener(s,'DataAvailable', @getData);
startBackground(s);
while toc <= Max_Time
if toc < i*(1/s_r)
else
timer(i, 1) = toc;
[Output1(i, 1)] = MyMexFunction;
i = i+1;
pause(0.01);
end
end
s.stop
delete(lh)
getData:
function getData(src,event)
global datastore
% hold on
datastore = [datastore event.Data'];
% plot(event.TimeStamps, event.Data)
end
I found that I have to include the pause(0.01) in the loop to allow the DAQ to populate the variable datastore, but this limits the rate I can sample the 2nd device at in the loop, and the pause function is somewhat unreliable over short time periods leading to missed samples.
Can anyone suggest an alternative to this set-up? I'm sure there must be a better way!
Also - What is the guidance on minimum pause time requires to collect samples - I can't find any documentation on this, and are there any alternative functions to pause that allow background data to be sampled?
Many thanks.

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by