07-05-2013 12:32 PM
Hi,
I have a DAQ that's acquiring 1 sample at 1 Hz. I am trying to get the program to continuously acquire samples but to output the average of every 10 samples, which I use at a later point in the program for calculations. I have found a lot of topics on the NI forums that discuss running averages but this is not what I am looking for. I have also found this link that shows a labview program that can acquire a given number of samples, average them and write to a file (2nd diagram from the top). This is very similar to what I need except for the part where it displays the mean within the case structure.
I am able to write the averages to a file or display them within the loop. However, I need to pass the average of every 10 samples out of the loop. In other words, the DAQ acquires continuously but at the end of every 10 seconds, the algorithm outputs the average of the data from those 10 seconds. Can anyone tell me if this is possible in Labview 2010 and what function will help me achieve this?
Thanks for reading!
07-05-2013 12:56 PM
Check this attached VI, and let us know, how close/far from your expectations??
07-05-2013 01:09 PM
Hi,
Thanks for the quick response. Your vi calculates the average but retains it inside the 'while' loop. I need to pass the average outside the loop every 10 seconds and use it for further calculations. I am fairly new to Labview so I don't think I have understood one part of that program. What does the DAQmx task outside the loop do?
07-05-2013 01:12 PM
Not bad moderator but, I'd probaly do something like this. Just to keep the Stop button responsive and use a notifier to signal the display and or file loops.
The "1, default" case just passes data through.
07-05-2013 01:40 PM
Jeff·Þ·Bohrer, thanks for the alternative but I as I mentioned earlier, I am fairly new to Labview and so I have not understood your vi entirely.
What do the notifiers do and how can I obtain the average out of the loop at the end of every 10 seconds?
07-05-2013 02:56 PM
Getting data out of loops (which is what you are trying to do) often uses Queues, which you can find on the Synchronization Palette of the Block Diagram. [A Notifier can be considered a form of Queue, one which holds a single element and has no buffering].
What you are encountering is a Design Pattern often called a Consumer/Producer Pattern (in LabVIEW 2009-2011, if you do a "Create New" and select "More" on the Getting Started screen, you will see the option to Create New from Template, and there are some Producer/Consumer Design Pattern examples for you to study -- the Templates in LabVIEW 2012 don't seem to have these examples).
What you want is two loops. Jeff has shown you the Producer loop -- this creates the averages every 10 samples and puts them on a Notifier (or a Queue, if you use that, instead) wire. The loop that isn't show is the Consumer Loop -- you branch the wire going into the top Producer loop and bring it into the Consumer loop, There you put the function that takes the data off that the Producer put into the Queue/Notifier, and do whatever you want to with it. This effectively moves the data out of the Producer Loop and into the Consumer Loop.
Another source for Consumer/Producer design patterns is to go to Support.ni.com. Type "Consumer Producer" in the Search box, and you'll find, among other things, some of the examples I mentioned from earlier LabVIEW releases.
BS
07-05-2013 03:54 PM
Bob_Schor, Thank you. That was helpful but there is one more problem. I am now able to see only one mean value when I run the program. I have attached a snapshot of the block diagram. I replaced the notifiers in Jeff's vi with 'queuing' elements. I also inserted a numeric indicator just to be able to see the mean value change every 10 seconds. However, it doesn't change. It remains constant as long as the program is running. The data I am acquiring is quite noisy and so the mean should be changing.
07-05-2013 03:59 PM
Here's the block diagram.
07-06-2013 06:51 PM
You are very close. Look at your Consumer loop -- you dequeue one element from the Queue, then pass it into a "Do Forever" loop that shows the single value. Put the Dequeue also inside the loop, and you'll have what you want.
The Producer loop will continue to put Means on the Queue. The Queue "wire" is a bit unusual in that data can pass "backwards" through the wire (it doesn't really -- the wire just identifies a conduit in which the data travels). Once the data is on the Queue, any Dequeue element (like the one you will move into the Consumer loop) will have access to the "conduit" and will be able to remove the data and do whatever you want with it (like display it on the Numeric indicator -- consider renaming that something more mnemonic, like "Mean Value").
One question that comes up with multiple loops is How Do I Shut Them All Down? Here, again, Queues are your Friends. Inside the Consumer Loop, wire the output of the Error Line coming from the Dequeue to the Stop indicator (this Consumer loop is so simple you don't need to worry about an Error Case statement). When you Release the Queue after exiting the Producer Loop (in response to pushing the Stop control), the Queue itself will disappear, and the Dequeue function in the Consumer Loop, which is waiting for a new value, will instead throw an error. Well, this error you will interpret as "The Queue Is Dead, Time to Stop Consuming", and by wiring the Error Line to the Consumer's Stop terminal, this will stop the second loop, and your program will exit.
Let us know if this answers your questions, and solves the problem you were raising.
BS
07-08-2013 08:35 AM
Bob_Schor,
I put the dequeue element inside the loop but now I get a mean value that changes every second and after 10 changes it remains constant until I terminate the program. It seems like the algorithm is calculating the mean incorrectly. I need the mean value of every 10 samples that are acquired by the DAQ.