Data acquisition toolbox - reading with different rates

18 views (last 30 days)
Hi all,
Let us suppose the following code:
dq = daq("ni");
dq.Rate = 25600; % 25,600 scans per second
ch9234ai0 = addinput(dq, "cDAQ1Mod1", "ai0", "Accelerometer");
ch9234ai0.Sensitivity = 0.0969; % Channel ai0: 96.9 mV/gravity (mV/G)
ch9203ai0 = addinput(dq, "cDAQ1Mod2", "ai0", "Current");
[data9174, startTime9174] = read(dq, seconds(10.0));
the code acquires data from a temperature transducer connected to a NI-9203 module and from an accelerometer connected to a NI-9234 module. Both modules are connected to a NI-9174 cDAQ. The temperature transducer measures the water temperature and the accelerometer measures the vibration in the suction tube of a water turbine. The code reads (read command) data from both devices during 10 seconds at a rate of 25,600 scans per second. So, 256,000 temperature values and 256,000 vibration values will be acquired.
it is worth noticing that the data acquisition toolbox lets me define only one data acquisition rate for the cDAQ, i.e., for all modules connected to the cDAQ. The problem is that there are modules that require high acquisition rates, while for other modules, low acquisition rates are sufficient. In the code, the rate of 25,600 scans per second is suitable for the accelerometer, but is much higher than that that is required for the temperature transducer. This causes a waste of the cDAQ bandwidth.
there are two possible alternatives to work around this shortcoming of the toolbox. The first one is to buy two cDAQs, and put the modules that require high acquisition rates in one cDAQ and the ones that require low acquisition rates in the other cDAQ. The second alternative, I guess, is to remove, for example, the first channel from the cDAQ (removechannel function) and read the data from the second channel and after, remove the second channel, insert the first channel and read data from it. However, this is a bit awkward and causes other problems.
does anyone suggest any other alternative to work around?
I thank you all in advance, cheers, Otavio
  3 Comments
Otavio Carpinteiro
Otavio Carpinteiro on 16 May 2021
Walter, thank you for your reply. The toolbox interface has changed. I'm using the new interface, for the functions (e.g., session creation) of the old interface are now deprecated. Mathworks does not recomend their use anymore. What I really wanted was the possibility to define different acquisition rates to different transducers, and that, obviously, depends on Mathworks to add this possibility to its new interface.
by the way, I have seen an old NI Labview program that captures data from different transducers at different rates. So, if data acquisition toolbox simply wraps the NI drivers of the NI modules then the toolbox would be able to do the same.
Walter Roberson
Walter Roberson on 16 May 2021
Ah, that is a quite new interface (R2020b and newer). I had not encountered it before.
When I look at the descriptions, it looks to me as if all of the items in a single daq() share a single rate, with the main question being about synchronization of the objects.
This leaves open the possibility that different daq() might perhaps be usable for the same vendor and same device, but I do not know at all if that is supported. The toolbox is not supported on my Mac. I might be able to run it in a Windows virtual machine, but I need to figure out whether I have any supported devices here.

Sign in to comment.

Accepted Answer

Otavio Carpinteiro
Otavio Carpinteiro on 31 May 2021
As I mentioned before, the data acquisition toolbox lets me associate a data acquisition rate to a cDAQ. So, my first try was to create, through the daq function, two daq structures associated to the same cDAQ. Thus, I could define two different data acquisition rates to the same cDAQ. MatLab didn't let me do that, issuing an error message. I tried other alternatives, but none of those satisfied me. So, I searched the internet looking for viable alternatives, and found the one described in the web page https://www.mathworks.com/help/daq/acquire-data-from-two-devices-at-different-rates.html.
The alternative describes exactly what I had tried first. So, I tried it again and it worked. I have no idea why it didn't work in my first try. Maybe I didn't clear the MatLab workspace between consecutive runs. So, the following code works and solves the problem:
dqH = daq("ni");
dqL = daq("ni");
dqH.Rate = 25600; % 25,600 scans per second
dqL.Rate = 1; % 1 scan per second
ch9234ai0 = addinput(dqH, "cDAQ1Mod1", "ai0", "Accelerometer");
ch9234ai0.Sensitivity = 0.0969; % Channel ai0: 96.9 mV/gravity (mV/G)
ch9203ai0 = addinput(dqL, "cDAQ1Mod2", "ai0", "Current");
[dataH9174, startTimeH9174] = read(dqH, seconds(10.0));
[dataL9174, startTimeL9174] = read(dqL, seconds(10.0));
I hope this message helps those who face the same problem in future...
  2 Comments
Otavio Carpinteiro
Otavio Carpinteiro on 1 Jun 2021
sorry, I didn't take your suggestion into consideration because I had unsuccessfully tried it before. However, a different situation occurred when I saw exactly what I had already tried in a MatLab web page. Obviously, I thought it worth giving it another try. Thanks, anyway.

Sign in to comment.

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 14 May 2021
What is your anticipated max. acceleration frequency bandwidth in your measurements? As is now, 25.6 kHz is quite high frequency. Maybe you don't need that much high rate of data to collect. maybe it is worth looking at this issue from this angle.
An alternative way is if you do need 25.6 kHz of sampling freq., then data collected for 10 second should not a big concern to process afterwards unless you are trying to embed a real time control.
Your anticipated alternative solution with additional module and switching on and off might create some inconsistencies in your acquired data if you're studying correlations between the two parameters, such as system responses (vibrations) against flow rates in the system.
What you are trying to achieve is an interesting procedure.
Good luck.
  1 Comment
Otavio Carpinteiro
Otavio Carpinteiro on 16 May 2021
Sulaymon, thank you for your reply. In fact, I do need this frequency to analyse some phenomena (eg, cavitation) in the turbine. The program I listed is just an example to expose the deficiency of the toolbox. The real program captures at least data from 10 transducers and the read is inside an infinite loop.

Sign in to comment.

Categories

Find more on Simultaneous and Synchronized Operations in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!