Example Code

Incremental Moving Average

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: This example uses a functional global variable to store the total sum of the numbers as well as the number of times it has been called. 


Description:

There are many ways to implement a moving average function. This example uses a functional global variable to store the total sum of the numbers as well as the number of times it has been called. Each time it's called it increments the iterations, adds the new value to the total and then calculates the current moving average.


 Requirements: LabVIEW 2012 (or compatible), Hardware: none.


Steps to Implement or Execute Code:

 

1. Just add the subVI to your code with the value you want added.
2. Wire true to restart to reset the total and iterations output.
3. Use "IMA Example.vi" as an example of how the subVI should be used.


Additional Information or References:

 

Incremental Moving Average FP.png

 

Incremental Moving Average sn.png


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

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

Comments
Ben
Knight of NI Knight of NI
Knight of NI
on

That looks like a running average and not a moving average to me.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
David_L
Active Participant
Active Participant
on

You might be right.  I thought they were pretty much the same, but I might be mistaken.