Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Ways to access data from DAQ using Matlab

I am trying to acquire data using DAQ card on a Matlab platform. On the web, it shows that there are three commands that are useful-getdata, getsample and peekdata. These commands seem to take too long time to execute than I would prefer. I wonder if anyone out there is aware if there is other commands to move the data from the DAQ card to the Matlab workspace?
 
Thanks in advance.
0 Kudos
Message 1 of 17
(6,202 Views)

Hi,

You'll need to tell us a bit more about what you're trying to do, and what your timing requirements are.  GETDATA, GETSAMPLE, and PEEKDATA are part of Data Acquisition Toolbox for MATLAB, which lives on top of Windows.  There's other products that operate on real time kernels that typically sacrifice throughput and ease of use in order to reduce latency.

All the best,
-Rob

-----
Rob Purser
Manager, Test and Measurement
MathWorks
rob.purser@mathworks.com
0 Kudos
Message 2 of 17
(6,190 Views)
I am using the Matlab M file to tune some parameters on my electrical circuit using the signal from the circuit. The signal from the circuit has a frequency content of around 60 Hertz or less. I would like to collect signal  using the DAQ card and analyze the data using Matlab. But the processed data then need to be output back to the setup in order to tune the parameter. My guess would be that the rate at which the signal is sampled then processed and finally ouput should be around 600Hertz  in order that the parameters are tuned fast enough to control the circuit.
 
But the three commands-Getdata, Peekdata and GetSample take about 2 to 3 ms to run on my computer. And sometimes it can go up to 6 ms. With these sort of speed, I can only process my data at the rate of about 200 Hertz. So I was thinking if there is a faster way to fetch the data from DAQ to the workspace of Matlab.
0 Kudos
Message 3 of 17
(6,182 Views)

Hi,

If I understand the problem, I think the solution is to continously acquire the signal, and call GETDATA while you are acquiring.  Start the acquisition, and let it run continuously in the background, grab data using GETDATA, and then process the result, and output to the circuit using PUTDATA.  You can continuously output a varying signal as well, but you just have to keep up with the D/A to do so.

-Rob

-----
Rob Purser
Manager, Test and Measurement
MathWorks
rob.purser@mathworks.com
0 Kudos
Message 4 of 17
(6,177 Views)
Actually that is what I have tried doing. However, when I timed the GetData and PutSample commands, together they take about 3ms to complete an iteration. I have put the two commands in a while loop. This means that the loop rate is limited to around 300Hertz. I would still need something faster. I wonder is it possible?
0 Kudos
Message 5 of 17
(6,172 Views)

Hello. 

What DAQ card are you using to take these measurements?  Any chance of posting the code here so our dedicated users can look into this?

Brian F
Applications Engineer
National Instruments

0 Kudos
Message 6 of 17
(6,154 Views)
I'm using PCI-MIO-16E4 for my data acquisition.
 
Currently, I am just trying to time the speed of the commands, so my code looks like this:
 
_________________________
 
ai = analoginput('nidaq','1');
ao = analogoutput('nidaq','1');
 
input_chan = addchannel(ai,0);
output_chan = addchannel(ao,0);
 
set(ai,'SampleRate',10000)
set(ai,'SamplesPerTrigger',inf)
set(ai,'TriggerType','Manual')
set(ai,'Transfermode','SingleDMA')
   
start(ai)
trigger(ai)
for i=1:1:1000  %move data to Matlab workspace 1000 times and process it
    tic
    if i<=10    
        %do nothing
    else
        in_data = getdata(ai,1);
    end
    putsample(ao, in_data);
    toc
end
 
_____________
0 Kudos
Message 7 of 17
(6,149 Views)
Hello. 
 
I don't see any glaring issues with your code.  However, I am not a terribly experienced programmer in Matlab and unfortunately do not have access to the toolkits that you are using.  However, from your description, it seems like it simply may be a speed limitation imposed by the software or the processor that you are using since our 6040E card allows sampling rates of up to 500 kS/sec.  What are the specs on the computer that you are using?  Have you considered using LabVIEW and our DAQmx driver?  It would be very easy to set up a task like this and could acquire at much faster rates. 
 
Let us know.  Maybe others that have access to Matlab will be able to help you better as well. 
 
Brian F
Applications Engineer
National Instruments
0 Kudos
Message 8 of 17
(6,124 Views)

You code looks fine.  You're using Traditional NIDAQ rather than NI-DAQmx, which changes the performance picture a bit.  I'm also not sure what version of Data Acquisition Toolbox and MATLAB you're using.  The acquisition continues in the background, so the time to execute the GETDATA function is the time to bring the data back into MATLAB.  As Brian mentions this may be a result of the hardware you're running. 

 

-Rob

-----
Rob Purser
Manager, Test and Measurement
MathWorks
rob.purser@mathworks.com
0 Kudos
Message 9 of 17
(6,110 Views)
Actually I have tried using Labview to acquire data. But the time taken to  get the data from DAQ card is also limited to several hundred hertz.
 
My computer is a P4 with 1 GB of ram and no antivirus running. Using data acquisition toolbox V2.7.
Another friend of mine was using a DAQ card probably from NI is able to get data from the DAQ card within microseconds using Visual Basics. This is a great difference of my result. As I do not really need very high speed, I just hope to improve the rate which I fetch data from the card.
 
I wonder if it is normal to take milliseconds to bring data from DAQ card onto the workspace of Matlab using a computer with specifications mentioned earlier?
0 Kudos
Message 10 of 17
(6,101 Views)