Using Data Acquisition Toolbox™ software, you can simultaneously start analog input and analog output. For example, you can create an analog input object ai and an analog output object ao for a sound card, and add one channel to each device object.
ai = analoginput('winsound'); addchannel(ai,1); ao = analogoutput('winsound'); addchannel(ao,1);
Queue data in the engine and start the device objects. By default the TriggerType is Immediate and this allows the trigger to execute immediately after start is issued. The start command will configure the objects and execute the trigger sequentially, leading to a delay between the start of the two operations:
data = zeros(4000,1); putdata(ao,data) start([ai ao])
When you pass ai and ao to start as an array, the first object in the array is configured and triggered, then the second object is configured and triggered. This is done serially, and therefore there is a certain amount of latency between the actual triggers of the objects.
In order to reduce this latency, you should use manual triggers. A manual trigger executes faster than all other trigger types (except hardware triggers).
set([ai ao],'TriggerType','Manual') data = zeros(4000,1); putdata(ao,data) start([ai ao]) trigger([ai ao])
The analog output object does not start outputting data until you trigger it. The analog input object will start acquiring data when start is executed, but will discard the data until you trigger it. In order to achieve the lowest possible latency, you should configure the analog input object's ManualTriggerHwOn property to Trigger:
set(ai,'ManualTriggerHwOn','Trigger') data = zeros(4000,1); putdata(ao,data) start([ai ao]) trigger([ai ao])
You can determine the time the analog input and analog output objects triggered with the InitialTriggerTime property. Calculate the time in seconds, between ai and ao:
aitime = get(ai,'InitialTriggerTime'); aotime = get(ao,'InitialTriggerTime'); delta = abs(aotime - aitime); sprintf('%d',delta(6)) ans = 2.288818e-005