Example Code

Simple Moving Average

Code and Documents

Attachment

Overview

This VI calculates the moving average of 5 elements of the input array. 

 

 

Description

This VI is programmed to compute the average of the previous 5 elements in an array. The first four iterations it averages based on the initial values passed to the shift register.

To take the average of more than 5 elements, additional shift register output terminals will need to be added.  Also, the value compared to the number of loop iterations should be changed to reflect the number of shift register outputs.

 

 

Requirements

LabVIEW 2012 (or compatible)

 

 

Steps to Implement or Execute Code

1. Download and open the VI "Moving Average_LV2012_NI Verified"

2. Set the values in the input array. You can replace it by a random function.

3. Run the VI

 

 

Additional Notes or References

Block Diagram

BD.PNG

Front Panel

FP.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
Nanxiong_Zhang
Member
Member
on

You can use the Mean PtByPt VI to complete similar functionality without the constraint for the number of element.

knowlittle
Member
Member
on

Thanks for the tip. I don't have MeanPtByPt in my basic LabView. Maybe it comes with Full Development. But I found Mean.vi and used it for easy moving average calculation.