LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to do a block average

HI everybody,

 

I have a DAQMX analog 12 channels input that feeds me with data with the sample rate of 100k and 1000 sample/channel. I can not increase the sample/channel because we need to save the raw data as is.

I want to do a block average (not running average) where I buffer every 600 data and then average it to get 1 value. I try with data queue but it seems I ended up with the running average. 

Can somebody help me with the issue?

 

Warm regards,

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

Add a conditional so that you only do the average every X samples.  Quotient & Remainder is good for doing that.  You should also store your last calculated average in a shift register for feedback node so you can keep using that value instead of whatever constant you use as the default.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 10
(2,851 Views)

@rioriorio wrote:

I can not increase the sample/channel because we need to save the raw data as is.


I do not understand what you mean by this. What does saving the raw data have to do with sample rate and samples/channel? I assume that you are continuously sampling and storing the raw data for some period of time. I would change from 1000 samples/channel to 600 samples/channel. Then you could get an average of the data every time you retrieve data.

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

"I would change from 1000 samples/channel to 600 samples/channel".

 

Hi johntrich1971

 

I can not temper with this setting, for time being, just consider it as my constraint.

0 Kudos
Message 4 of 10
(2,785 Views)

You haven't provided the code that you use to collect the data, so I don't know whether you are using 2D Dbl Arrays, 1D Arrays of Waveform, or something else.  I also don't know if you are using Producer/Consumer Design or trying to do everything in a single loop.

 

If you had the data as 600-sample "chunks" from a DAQmx Read, the process would be very simple -- every time you get a Chunk, split it, sending one Chunk to the "Save the Data" routine to write to disk, and send the other to the "Average 600 points" to give you your average.  With 1000 points, you'd do the same thing, but the "Average 600 points" routine gets more complicated.  Here's one way to begin to approach it:

  • You get 1000 new points.  You may have N Points "left over" from the previous call (initially, N will be 0).
  • Combine the previous N +1000 points, and split out the first 600.  Average them and send to where ever they need to go.
  • Now look at the remaining N + 400 points -- is this at least 600 points?  If so, repeat the previous step.  Otherwise, you are done until you get the next 600 points.
  • Note that to do this, the routine will need to be coded as a Functional Global, i.e. a While Loop with a Shift Register holding an Array of Points (initially an empty Array, but later holding the N elements -- you tag on the 1000 elements at the end of this Array, and remove the 600 elements from the front) and with the Stop Terminal wired to True (so it runs exactly once).  You should be able to work this out.

Bob Schor

0 Kudos
Message 5 of 10
(2,765 Views)

Hi Bob,

 

This is currently part of the code I am working on. I hope I could find a better way to make the block average. the current method I am using is time-consuming.

snippet.PNG

 

Download All
0 Kudos
Message 6 of 10
(2,741 Views)

Your code is very different than what you described. You are not averaging 600 data points. You are taking the average of 1000 data points every 600th reading. Did you even try the code that crossrulz suggested?

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

No.  He's taking the average of how many data points happened to have been acquired since the last loop iteration.  Then sending that average to the other loop every 600 loop iterations which may or may not represent 600 data points.  It is almost certainly not the average of 600 points or 1000 points.

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

@RavensFan wrote:

No.  He's taking the average of how many data points happened to have been acquired since the last loop iteration.  Then sending that average to the other loop every 600 loop iterations which may or may not represent 600 data points.  It is almost certainly not the average of 600 points or 1000 points.


I made the assumption that he was setting Samples/channel to 1000. He's telling the DAQ to wait forever until there are Samples/channel data points and then read those Samples/channel data points, then averaging those data points and sending every 600th average to the other loop.

0 Kudos
Message 9 of 10
(2,698 Views)

@rioriorio wrote:

"I would change from 1000 samples/channel to 600 samples/channel".

I can not temper with this setting, for time being, just consider it as my constraint.


What else in the system cares about the number of samples you read at a time?  We keep harping on this because it is BY FAR the simplest route to get to the requirements you have told us so far.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 10
(2,692 Views)