DAQ: how to synchronize timing of background acquisition (startBackground) and other Matlab operations

10 Ansichten (letzte 30 Tage)
I acquire digital data in background using a National Instruments device.
After initiating background data acquisition, I perform other operations for which I also get the timing by using tic toc (or GetSecs from Psychtoolbox).
Is there a way to precisely align (down to milliseconds or less) the timing of the data acquired in background with the timing of the other operations?
In other words, in the example below, time_operation1 and event.TimeStamps are measured with different clocks. How can I align them?
device = 'Dev1';
s = daq.createSession('ni');
addDigitalChannel(s, device,'port0/line0','InputOnly');
addAnalogInputChannel(s, device,0,'Voltage');
s.IsContinuous = true;
lh = addlistener(s,'DataAvailable',@(src,event) manageData);
startTime = tic;
% other operations here ...
a = 1; % operation1
time_operation1 = toc(startTime);
% etc ...
function manageData(event)
global data
data = [ data;...
[event.TimeStamps, event.Data(:,1)] ];
Additional comments:
  • the variable event.TimeStamps(1) is always zero.
  • event.TriggerTime is a time stamp representing the absolute time the acquisition trigger occurs.
  • The function clock or now might be used to get a time stamp of the other operations and then measure time differences relative to event.TriggerTime. However, this is probably not a good approach because (from clock Matlab documentation) "The clock function is based on the system time, which can be adjusted periodically by the operating system, and thus might not be reliable in time comparison operations".
  • Even assuming that event.TriggerTime is reliable, using a single time point for aligning the timings is not enough for longer data acquisitions. The two clocks (the one of the NI device and the tic toc) are different, meaning that 1 sec will not be exactly the same for the two clocks, such that an offset of one clock over the other will build up over time.

Antworten (0)


Mehr zu Data Acquisition Toolbox Supported Hardware finden Sie in Help Center und File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by