Moving Average Compute After Sampling | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver

Friday April 3rd, 2020
Support: LabJack engineers available through email and chat.
Shipping: We are processing and shipping all orders.
Stock: 55/56 products in stock. More details.
Supply Chain: Some disruptions. More details.

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.