Unable to set precise sample rates when acquiring data using NI cDAQ-9171 USB chassis

I'm writing a program for acquiring analogue data using a NI cDAQ-9171 USB chassis. I'd like to have the flexibility to acquire data at a range of sample rates, however I'm unable to set the sample rates precisely at certain sample frequencies.
Here is the code I'm using to configure the data acquisition object:
d = daqlist;
d = d(1,:);
s = daq('ni');
ch = addinput(s, d{1,2}, 0:31, 'Voltage');
s.Rate = sampleRate;
For some sample rates (100, 200, 400, 800, 1000Hz), I am able to set the sample rate precisely. E.g. if I set sampleRate=500; and then I view the s object in the command window, I can see that the s.Rate property is exactly equal to sampleRate (i.e. 500)
However, for other sample rates (300, 600, 900, 1100, 1200Hz etc.), the s.Rate property can't be set precisely to these frequencies. E.g. if I set sampleRate=600; and I view the s object, I see that s.Rate=600.0015Hz
If anyone could explain what's happening here to me, or knows a way around this problem, it would be much appreciated!
(The code uses the Data Acquisition toolbox and is based on this example Capture Data with Software-Analog Triggering - MATLAB & Simulink - MathWorks United Kingdom)

4 commentaires

hello Megan
I believe this is related to the fact that not all values that you ask for can be exactly implemented on the hardware.
the reason behind that is that sampling is linked to the clock rate - divided by a integer , and that value becomes the "true" sample rate. if you know the clock rate , then you can probably predict which frequencies will be "exactly" implemented and which ones will be rounded to the nearest realisable value.
maybe I have a numerical example :
assuming the clock rate is Fs = 80 MHz
the integer divider to get closest to 600 Hz is b = 133333
then the hardware sampling rate is Fs / b = 600.0015 Hz , which is what you have on your display
Ah I see, thank you very much for explaining!

Connectez-vous pour commenter.

Réponses (0)

Produits

Version

R2021a

Question posée :

le 24 Août 2021

Commenté :

le 25 Août 2021

Community Treasure Hunt

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

Start Hunting!

Translated by