LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need to use the mean.vi to average values every ten minutes

Hi, I am working on a project and am very new to labview. I have one day to get my experiment running and haven't had much success. I've attached my VI so far. The main problem I have is that the experiment is two weeks long. I have 4 sets for differential voltage inputs which I am filtering, passing through a formula, and passing into a mean.vi. This is all within a while loop. I want to be able to write the mean values over the period of 10 minutes so I do not have a million data points after two weeks. The problem I'm having is that I do not know how record the value from the mean.vi then reset the data in the while loop and do it again continuously for two weeks. I hope this makes some sense to someone. I'd appreciate any help I can get and thank you in advance.

 

 

0 Kudos
Message 1 of 6
(3,577 Views)

Hi,

 

it's hard to see what's really going on in your program with all those express vis that virtually none of us ever use. I guess that's why anyone answered yet.

 

What I see:

The contents of the for loop should go into your measurement loop. Write the data whenever it becomes available, not after the whole acquisition has stopped. In your current setup only 4 values will be in your file after those weeks.

If you don't want to store every mean but a mean of x means you should feed your mean into a shift register and keep averaging for x iterations. Then write to file with in every xth iteration, you can achieve this by putting your write to file into a case structure monitoring the iteration counter.

 

Regards

Florian

0 Kudos
Message 2 of 6
(3,559 Views)

Florian,

 

I've modified the VI using your advice. I think I have an idea where this is going but I'm not too sure what to do next.

 

I think if I run the mean vi for two weeks while its inside the while loop, the last value that comes out of it will just be the average value for the entire test and not the average value for the last ten minutes only. I guess I'm not doing something right with the shift registers.

 

I'm not too sure how to make the case structure true every ten minutes or every xth iteration. I humbly request further guidance.

 

Yousef

0 Kudos
Message 3 of 6
(3,546 Views)

Hi Yousef,

 

In order to create intervals within your for loop, you will need to add some sort of timing functionality in the loop. The quick and dirty method I would recommend would be to simply add a 'Tick Count' function to your data acquisiton loop. This function will keep track of the elapsed time within the loop (in milliseconds). You can use a comparison to check if the tick count has exceeded 10 minutes. If so, write data out of the loop and start again. I've included a link below with detailed information on loop timing and shift registers.

 

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

 

I understand you're on a tight schedule with your project, but in the future I would avoid using so many Express VIs. Although these VIs can be convenient for small applications, it is usually much more beneficial to lay out the neccessary DAQmx functions manually in order to ensure your code will execute properly and avoid unncessary execution time. The second VI you posted is already looking like a much cleaner piece of code than your first, so keep up the good work!

 

Andy C.

Applications Engineering

National Instruments

0 Kudos
Message 4 of 6
(3,526 Views)

Attached is an example of what i think you're trying to do. The way I am showing you is not the best way to do it, but I think it will be the easiest for you to understand. I say not the best way because it's not very memory efficient. You are building arrays and holding all that data in memory for 10 minutes, then averaging it when you write to the file. If you have very high data rates you will not want to do it this way. I think it should at least give you an idea to get over the hump you're stuck on (how to restart the averaging after the file is written). Everyone is telling you to use less express VIs...they are right. However, I used one in my example I'm giving to you Smiley Surprised. This is the only express VI I use: the elapsed timer VI. It handles counting down and returns a boolean when the timer expires, and auto-resets and starts counting down again. This express VI isn't a "bad" one because it isn't open and closing resources like many of the other express VIs do (DAQ assistant, file writing express VIs etc).

 

Anyways, hopefully this helps.

 

Edit: woops, i forgot to change my constant from 5 seconds back to 600 seconds to represent 10 minutes. 

0 Kudos
Message 5 of 6
(3,510 Views)

Don't forget the 2wks out code....don't understand your need in averaging? Your 1st post vi wants the average every hour, then you want every 10 mins..Do you want a total average at those times or just the readings at the times specified?

Spoiler
2wks_BD.png
0 Kudos
Message 6 of 6
(3,496 Views)