Moving Average Compute After Sampling | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver

LabJack is closed November 26 and 27 for the Thanksgiving holiday.

Moving Average Compute After Sampling

This script reads analog inputs and computes the moving average after each sampling interval.  This script is particularly useful for Modbus polling applications that need to be sure that each "moving average" value that gets read is the most up to date value. The script can be customized by editing the constants:

local sampleIntervalHZ = 10 -- Sampling interval in HZ
local numSamplesToAverage = 100 -- Number of samples to cached & average
local channels = {0, 2} -- Which analog inputs/registers to read & average

To assist with determining maximum sampling rates and buffer sizes, digital I/O lines FIO4-5 on T4s and FIO0-1 on the T7 are configured to output waveforms that can be read with an oscilloscope or logic analyzer. As a really low-cost solution, LEDs can be installed and looked at to see how bright they are and used to determine how much idle time the script has.