# math::AvgN

    sys::Obj
      sys::Virtual
        sys::Component
          math::AvgN

`public class AvgN` `[niagaraIcon="module://icons/x16/control/math/average.png"]`

Modified Moving Average math object

      out = [(n-1)*out + in]/n = (total + in - avg)/n

      where total = approx. running total of last n samples
            avg   = last computed average = total/n

      Note: 1) the "avg" value is "seeded" with the "in"
               value at startup or whenever "n" changes
            2) the "total" value is "seeded" with (in * n)
               at startup or whenever "n" changes
            3) boolean input "reset" resets the object to
               return to first execute cycle state, and avg
               and total are re "seeded".  This may be useful
               to invoke in an application where large step changes
               of "in" are expected and "n" is a high value, to prevent
               output lag of the input.

      For large step changes in values, the "out" value will asymptotically
      approach the "in" value.

in

  `public property float in`

  value of in is added to average computation every execute cycle

numSamplesToAvg

  `public property int numSamplesToAvg [min=1, config]`

  number of samples to average. One new sample is read every execute cycle.

out

  `public property float out [readonly]`

  the average value updated every execute cycle

reset

  `public property bool reset [readonly]`

  reset is invoked to re-initialize the averaging

changed

  `public virtual override void changed(Slot slot)`

  Behavior to execute when a property is changed externally

computeAverage

  `public void computeAverage()`

  average in a new sample

execute

  `public virtual override void execute()`

  Execute is called once every scan.

start

  `public virtual override void start()`

  Callback when component is first started in an app, before the first call to propagateLinksTo() or execute().