LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Average (Mean) of streamed digital data

Solved!
Go to solution

I have built some Labview code that receives streamed 300Hz digital data from a piece of hardware over an Ethernet interface.  I display the data to screen and write it to a .tdms logging file.  All of that code is working.  

 

I would like to perform a 2Hz average (not a moving average) on blocks of the data and display and log at that rate.  This new code would need to take the average of 150 samples at a time and output at the new effective 2Hz rate.

 

I assume the mean block would be the way to go, but am struggling a bit with how to collect the 150 samples at a time out of the streaming 300Hz data, perform the mean/average calc and then grab the next 150 samples and do the same.  To reiterate, I do not want a moving/sliding average, but rather the result would be an average of the 300Hz data decimated to 2Hz, so an average of 150 new samples at a time.

 

I appreciate suggestions on the best way to approach this problem.

 

JJ

0 Kudos
Message 1 of 8
(579 Views)

Hi Joel,

 

what have you tried so far?

 

One possible way:

  1. Write the samples into a queue.
  2. Have a consumer read 150 samples from the queue and average them. Output the result to another queue.
  3. Repeat item 2.

Another way:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 8
(575 Views)

Maybe something like this:

a.png

 But you have to do something about the fact that the 1st output will be garbage.

0 Kudos
Message 3 of 8
(551 Views)
Solution
Accepted by altenbach

@Joel(JJ) wrote:

I have built some Labview code that receives streamed 300Hz digital data from a piece of hardware over an Ethernet interface.  I display the data to screen and write it to a .tdms logging file.  All of that code is working.  


I will refrain from offering specific solutions until we actually know how the data arrives. Do you get one point at a time (would be very inefficient if each ethernet packet is 99% headers!) or multiple points?

 

Maybe you could show us a simplified VI showing the gist of your current processing (display on screen & log to file). Should the new code display and log both (original and reduced rate), or only at the reduced rate? What is the datatype of the data Integers? floating point? How many bits in resolution?

 

In any case, to do an average of a fixed number of points, all you need is one or two scalar shift registers for the sum (and also for the current N, unless you can derive it from the iteration terminal) No need to build arrays in memory. (f the data is integer, e.g. U16, make sure that the sum does not overflow by upgrading the type before summing)

 

altenbach_0-1713543669158.png

 

 

 

0 Kudos
Message 4 of 8
(529 Views)

Hello, JJ.  How are you collecting, saving, and plotting the data now?  It sounds like you might be doing "single sampling" at 300 Hz and streaming these data to disk.  What you can do is write a "Down-Sample" VI that is a Producer -- it "collects" each sample and saves it in an Array, keeping track of the Array size.  When the size hits 150, it averages the Array, put the Average in a Queue (or Stream Channel Wire) to the Producer, and re-initializes the Array to an empty Array.  This should take microseconds to do, and you have more than 3 ms until you'll get another sample to worry about.

 

I implemented something like this in one of my first LabVIEW Projects.  The lab was acquiring data much faster than they ever planned to use it -- the main use was to provide a 20 points/sec Chart to show the (relatively slow) progress of the System under Test.  If memory serves, we were sampling at 1 kHz, so every 50 samples, my Array filled up and I dumped it.  Hmm -- now that I think about it, I might have been "cute" and used a Finite-sized Queue to hold the data, noting when the Queue filled up so I could dump the contents into an Array, clear the Queue, and output the Average of the Array to my Consumer.

 

Bob Schor

 

Bob Schor

0 Kudos
Message 5 of 8
(517 Views)

Thanks to all who have taken the time to reply.  I do not have access to my Labview this weekend, but will look at implementing some of these approaches next week.  To answer a few of the questions, this data is "real time", so it is point by point at 300Hz.  The hardware is outputting numerous measurements at the 300Hz rate, though I'm only interested in the averaging function on a few of them.  The data type are floats.  As far as what I was trying, I was attempting an array approach, but obviously had implementation issues as it wasn't working properly.  

0 Kudos
Message 6 of 8
(477 Views)

I went with altenbach's solution as it was the simplest to incorporate in my current code.

 

I wanted to mark as solution, but didn't see an option to do that.


Again, thanks to all who took the time to provide solutions.  Much appreciated!

0 Kudos
Message 7 of 8
(432 Views)

@johnsoja wrote:

I wanted to mark as solution, but didn't see an option to do that.


OK, I marked it for you. 😄

0 Kudos
Message 8 of 8
(413 Views)