LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array Averaging - help!

So I am using some Measurement Computing hardware in LabView to scan some temperatures. The scan VI takes a data reading each time a loop is read (which is a few times a second) and this data is sent out in an array. The problem is, my data log gets QUITE big after about a minute (with so many readings!).

So I really need to average this data. Since I am new to LabView, I am not really quite sure how I can "hold" the data between loops and average the data according to a user defined value. That way, each time it writes to a text file the value written is the average value.

How can I go about doing this? I am quite lost - but THANK YOU for helping.

Steve L
0 Kudos
Message 1 of 14
(6,434 Views)
Hi stephen
 
What kind of averaging would you like here. You say that you are acquiring in a loop then outputting into an array, how often would you like to average out there temperatures. Are you looking for average temperature per second or per 10 seconds or per minute for example -  this will be decided by what kind of temperature change, trend and sensitivity you are hoping to measure.
 
A couple of other things: At the moment are you writing direct from the array to a text file and do you have any timing in your acquisition loop to control the acquisition?
 
Would it be possible to attach the VI that you are working on so I can take a look and try to advise a bit further and more accurately.
 
Best regards
Graham Green

Sr. Product Marketing Manager

National instruments
0 Kudos
Message 2 of 14
(6,430 Views)

The attached vi is one way to accomplish what you desire.  It stores data into a queue in the producer loop (top loop).  The consumer loop (bottom loop) dequeues the data and stores it into an array.  When the array is of a certain size, calculate the average and clear the array.  You can write the avg to a file.  This continues until you cause it to stop.

 

- tbob

Inventor of the WORM Global
Message 3 of 14
(6,401 Views)
Hi guys,

Thanks for the help.

Tbob, it worked great. I was wondering though that since it is an array of data outputted from the scan (basically the data of the channels is in an array each time it is sent out), I was wondering if the program averages only one data point of if I need to use that program in succession for EACH element in the array.

Thank you!

Stephen Lizcano
0 Kudos
Message 4 of 14
(6,327 Views)
I'm not quite sure what you mean.  You want to average on one data point only instead of 10?  You can change the constant 10 to 1, but the code would be wasteful.  Simply remove the part that does the averaging and just store your data points into an array.
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 14
(6,298 Views)
Hi tbob,

What I meant to say was that I have 4 channels in the array for 4 different temperature measurements. Does that VI average all 4 channels separately over time so i can write them to a file?  That's my ultimate goal here, but y labview skills are sub par. 😕

Stephen L
0 Kudos
Message 6 of 14
(6,166 Views)
My vi just generates random data to show you how to do averaging.  I don't know what your vi looks like.  If you have 4 channels all in one array, then the code will take the average of all 4 channels all together, not separately.  If you want to have 4 average values, one for each channel, you have to produce 4 arrays, one array for each channel.  Your code would have to read channel 1 and append the data to array 1, then read channel 2 and append to array 2, etc.  When the number of elements reaches your limit, then call the code to average each array separately.  It would help if you attached your code, or a relevant part of it here.
- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 14
(6,157 Views)
Hi tbob,

I included a picture of my VI block diagram to show you a bit of what I was doing. Basically, I replaced the random number generator with the actual scanning temperature VI itself. The dequeing part of the VI is the part that averages it.

So if I'm understanding you correctly, I should decimate the data into 4 separate arrays and then proceed to average them that way according to your original VI?

I've included the VI and the library used if you would like to look at it directly as well.

Thank you for your help,

Stephen L
0 Kudos
Message 8 of 14
(6,145 Views)
Since your scan subvi is just a call to to DLL function, I can't tell what it is doing.  It seems like you are scanning several channels, from low channel to high channel.  Is this the 4 channels you mention?  Does it retrieve data from channels 1 through 4 in order and then start at 1 again?  If this is so, you would need to decimate the array into 4 separate arrays and take the averages of each one, just as you have stated.
- tbob

Inventor of the WORM Global
0 Kudos
Message 9 of 14
(6,124 Views)
Yes, basically every time the loop executes TinScan.vi it scans the channels and outputs the channels, high to low, in an array and does not execute until the very end.

Since it doesn't start again until the loop executes again, I'm not sure if decimation will work - but I will try it out right now and let you know how it goes.

Thanks for the insight!
Steve L
0 Kudos
Message 10 of 14
(6,122 Views)