From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Aggreagation Labview over 3s or 10min

Solved!
Go to solution

Hi forum,

 

I am using a NI9220 with 100ks/s/ch  for power monitoring where i am calculating the RMS , THD values of a current and votlage wave with the rms. and thd vis. I woulde like to implement a aggreagation of 3s and 10min  and write the values  to file every time the average  is calculateted. 

Is there a way to do this in labview mabye with the moving average example? 

 

Thanks

Martin

0 Kudos
Message 1 of 10
(2,900 Views)

Hi,

 

This can easy be done with a producer/consumer design pattern.

 

http://www.ni.com/white-paper/3023/en/

 

There is an example shipped with DAQmx - the analog input continuous example. Set "samples to read" to 300k and the aquisition rate to 100kHz. That let the aquisition loop execute exactly every 3s - because DAQmx Read waits until 300k data is there. Average all values and write them into a queue.

 

The consumer loop (see link) dequeues automatically every three seconds. There you can write to a file. Collect the data here for 200 cycles (10 min), make an average of this array and you have you 10 min average value.

 

A good file format is the .tdms

http://www.ni.com/white-paper/3727/en/

 

Regards

René

0 Kudos
Message 2 of 10
(2,840 Views)

hI rESCHRI,

 

thank you very much that helped me a lot it is now working with the the producer/consumer design patter, but I have one issue: 

I implement the Producer/consumer application to my current programm see the picture below:

capture.PNG

I have now 2 DAQmxRead vi one is for continously daq (samples to read 100)   read and the other one with the producer consumer loop (samples to read 1000). How i could run and stop both application at the same time. Would be great if you could have a idea for this.

thanks again 

Martin

0 Kudos
Message 3 of 10
(2,821 Views)

Hi,

 

Somthing is unclear here:

 

You have two different DAQ-Devices and DAQ-Tasks. You cannot have two tasks for the same Analog Inut. For instance, you cannot have analog input A0 to A3 in one task and A4 to A7 in another.

 

A Continous Analog Input Task means that the driver of the card sets it to continous aquisition with the parameter you´ve choen. The DAQmx Read does nothing but read out the data from the RAM of the computer.

 

So I do not know what you mean by "having to DAQmx Read" unless you have two devices which I cannot figure from your Screenshot.

 

What else concerns me: you stop the aquisition (DAQmx Stop Task) in EVERY loop iteration, meaning you do not have a continous aquisition. The task is stop, the loop iterates again, and DAQmx Read restarts the task. Use the Stop-VI AFTER the loop

 

The easiest way to stop multiple loops is the use of variables:

http://www.ni.com/white-paper/7585/en/

 

Regards

René

0 Kudos
Message 4 of 10
(2,785 Views)
Hi Rene,
Thanks for the info I thought I could use 2 daq tasks for the same analog input for example one waits 10k samples (continuously data logging by 100ks sampling rate) other 300ks samples (3s) to read.
Is there another way to get the aggregation like building a buffer over 300ksamples creat average put it into consumer loop and write it there to file?
Thanks
Martin
0 Kudos
Message 5 of 10
(2,760 Views)

Hi,

 

Just as an update, you can have more than one task for the same analog input source depends the hardware you are using, but I didn´t want to complicate things.

 

What you want to do (at least I think so) aquiring on one pysical channel - only one anaolg input port is connected. Please confirm that if I am right.

 

And now you want to read out the buffer two times: one time a 10k piece and after 3s then a 300k piece.

 

When you use DAQmx Read, the data is taken out of the buffer.

 

You want the driver to read out 10k every 3s, while the driver buffer(!) continues to store values until 300k is reached.

 

This neither necessary nor possible to my knowlege. Therefore, you have LabVIEW to implement whatever logic you need. In your VI!

 

Read your values from the buffer with DAQmx Read. Then, store them, average them, accumulate them.

 

"Is there another way to get the aggregation like building a buffer over 300ksamples"

 

There are plenty of ways to do that:

 

For starters:

Passing Data Between Loop Iterations in NI LabVIEW

http://www.ni.com/gettingstarted/labviewbasics/shiftregisters.htm

 

Regards

René

 

0 Kudos
Message 6 of 10
(2,740 Views)

Hi Rene,

 

ok that helps me a lot. 

Do you have a idea how to create this feature i would probably need an array that stores the data (300ks) and every time the array is full calculate me in another loop the average and store it into another array and then write it to file?

 

Thanks a lot 

Martin

0 Kudos
Message 7 of 10
(2,679 Views)

Hi,

 

have a look at this:

 

http://www.ni.com/white-paper/7188/en/

 

what you need is a so called ring buffer. You store data for a certain time and overwrite the oldest with the newest one. You can implement this with the library provided. You have an array of a fixed size for that.

 

Regards

René

0 Kudos
Message 8 of 10
(2,671 Views)

Hi Rene,

 

thank you very much! I used the ring buffer and implement a logic so i record 300ksamples calculates the rms and thd values continously and every 1s it writes the file to a text file. Looks like its working but you have a idea to size the elements in the array now i just wait 1s (buffer is full) and then start callculating. I attached the logic:

0 Kudos
Message 9 of 10
(2,653 Views)
Solution
Accepted by topic author Martin88

Hi,

 

you configure the simulate blocks to produce as many data points as you want per second, then you add a timing to the loop to execute every second.

 

http://www.ni.com/white-paper/4120/en/

 

Regards

René

0 Kudos
Message 10 of 10
(2,624 Views)