Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI USB-6218 sample rate inconsistent?

I'm using MATLAB to read data from the NI USB-6218. I do know for sure that it is reading data correctly.

 

I can read 1000 samples of data in 0.22 seconds. It takes 50.32 seconds to read 5000 data points. For 10,000 it's 126.74 seconds. I'm storing all of these data into one matrix.

 

Is it possible that the device is defective, or is it my code? I also posted a thread on MATLAB's forum asking if it's just the language that's slowing it down.

 

Here's my code:

 

ai = analoginput('nidaq','Dev2');

ai0 = addchannel(ai, 0);

ai.SampleRate = 1000;
start(ai);
pause(.2);

for i = 0:1:1000
    ai_value = getsample(ai)
end

% Clean up
delete(ai);

 Again, the code works, and I'm 100% sure it's reading everyting correctly. It just gets slower and slower as more data comes in.

 

Any idea why this is happening?

Thanks.

0 Kudos
Message 1 of 21
(4,649 Views)
I am very inexperienced with matlab but it appears to be your code. Are you really reading one sample at s time? That means you are using a software timed acquisition.
Message 2 of 21
(4,645 Views)

I'm pretty sure. According this this, getsample() returns exactly one value for each channel. I only have one channel, therefore it should only be returning one.

0 Kudos
Message 3 of 21
(4,633 Views)
The number of channels is irrelevant. If you want s consistent sample rate, collect multiple samples at a time as a hardware timed acquisition.
0 Kudos
Message 4 of 21
(4,630 Views)

How can I accept multiple samples at a time? I need them in real time, so I don't think that would help me anyway.

 

How could I make it a hardware timed acquisition though? That seems like a good idea.

0 Kudos
Message 5 of 21
(4,628 Views)
I don't know what you mean by real time. To me, that implies a real time os.

Look at the getsamples function.
0 Kudos
Message 6 of 21
(4,624 Views)

Aren't all OSs real time? You do mean Operating System, right?

 

What I mean is that I want to gather the samples as fast as possible. Techincally it only needs to be about 200 Hz. But I was a new data point 200 times every second, and I need to process it it at that rate as well. So I can't just accumulate a bunch of data with timestamps.

0 Kudos
Message 7 of 21
(4,621 Views)
Very few os's are real time. Windows, mac, Linux are not.

For details on using their software, ask for help from the mathworks. You do need to understand the basics. If you specify a sample rate, the time to acquire is based on the number of samples you request. Simple arithmetic. Samples divided by samples per second is time to acquire. Your current method is accumulating s bunch of data with irregular timestamps.
0 Kudos
Message 8 of 21
(4,619 Views)

Hm... So if I increase the sample rate in relation to the samples desired then it should work?

 

If it does, great, but it doesn't help me long run. Ideally this thing would need to run for 10+ minutes, and I can't do it based on number of samples, I would really need to do it continuously as long as it's running...

 

Sorry I'm so confusing.

0 Kudos
Message 9 of 21
(4,616 Views)
You need to increase the number of SAMPLES. Each acquisition would have a sample count. You acquire in a loop. Run the loop as long as you want.
0 Kudos
Message 10 of 21
(4,611 Views)