Example Code

Calculate Averages For Multiple Data Runs

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
To take data from an acquisition device and only calculate an average of the data when the "Log Data" button is manually turned on.

Description:
In some instances, a user may want to take the average of several data points in LabVIEW.  However, the user may only want to average data once a signal voltage has settled or a certain event happens.  This example allows a user to take data from an acquisition device and only calculate an average of the data when the "Log Data" button is manually turned on.  When this button is turned off, the average of all the data points during the time in which it was turned on is calculated and displayed.  In the example code, the Simulate Signal  Express VI is used and can be replaced with either the DAQ Assistant or  DAQmx VIs to be used with an actual data acquisition device.  After numerous data runs are collected and averaged, the user may want to send these averages to a file or use them elsewhere in the program.  By clicking the "Display All Logged Means" button once logging is turned off, all of the calculated data can be transferred elsewhere in the program.  In the example, this array of averages is sent outside the main While Loop and simply displayed on the front panel.

Steps to implement or execute code
To implement this example:

  1. Open the Log and Calculate Mean.vi
  2.  To begin collecting data (in this example, simulating data), click the Run arrow.  The VI will continuously display data.
  3.  When you are ready to begin collecting the data to be averaged, press the Log Data boolean switch.
  4. Once you are through collecting this data, press the same boolean switch again to display the average from the data run.
  5. To collect data for another run, simply press the button again to turn the logging on and off.
  6. Once all data runs have been completed, press the "Display All Logged Means" button to send the array of calculated means elsewhere in the program (or to a file, for example).
  7. Press the Stop Program button to completely stop the entire VI.

To execute this example:

  1. Install the required software.
  2. Open the VI and refer the Implement Steps


Requirements
Software
LabVIEW 2012 or compatible

Hardware
-

 

fp.JPGbd.JPG

**This document has been updated to meet the current required format for the NI Code Exchange.**

Regards,
Austin S.

National Instruments
Academic Field Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.