MATLAB: How to use FIFO memory of DAQ

analoginputData Acquisition Toolbox

i have a DAQ which has a capability to store 4095 samples in FIFO , i want to store some data and which comes from a sensor via loop and at the end i want to display the stored data ,
at present i a m using start (ai) and getdata syntax inside the loop which making program to run too slow , i.e. every time i run the loop to change the pixel address i have to trigger(start(ai)) and getdata.
any one any idea ?

Best Answer

The FIFO is automatically managed by the DAQ driver. Where you have the option of:
  • Single Sample Function
  • Multi Sample Function
When you use the multi scan funtion, you have to set:
  • Number of Samples (< FIFO mem)
  • Frequecy Rate
So, you have a vector of samples with scanned every 1/Rate seconds in real-time.
Now, In Data Acquisition Toolbox, you could do that
idChannels = 0; %%for more channels = 0:2;
chRate = 44100; %%rate for all channels [sample/s]
FIFO = 4095; %%FIFO size [samples]
acqTime = FIFO/chRate/length(idChannels); %%acquisition time [s]
ai = analoginput('nidaq', 'Dev1');
addchannel(ai, idChannels);
set(ai,'SampleRate',chRate);
set(ai,'SamplesPerTrigger',FIFO);
% Execute acquisition.
num_iterations = 100;
data = zeros(num_iterations*FIFO);
for i = 1:num_iterations,
start(ai);
wait(ai, 2*acqTime); %%wating time 2*acqTime [s]
data((i-1)*FIFO+1:i*FIFO) = getdata(ai);
end
% Delete the object out of the loop.
delete(ai)
clear ai
plot(data);
When you acquire a sample (block of 1 sample) in a loop, the acquisition is very slow cause the PC hardware interruption is very slow. If you want to have a fast acquisition loop, you could get better performance on a Real-Time Operative System, but you only increase the performance in 20%. If its not enought for you, I recommend you to use a dedicated hardware like micro-controller, DSP or FPGA, to implement your acquisition and control loop.