Skip to content

math.MathUtils.Function.simpleMovingAverage

Christian d'Heureuse edited this page Jun 7, 2026 · 2 revisions

dsp-collection / math/MathUtils / simpleMovingAverage

Function: simpleMovingAverage()

function simpleMovingAverage(
   a, 
   windowWidth, 
   shift?): Float64Array;

Defined in: math/MathUtils.ts:93

Calculates the simple moving average (SMA) over an array of numbers.

Each element of the output array contains the mean value of the window centered at that position in the input array. When the window width is even, the shift parameter specifies whether the resulting position is 0.5 to the left (shift = false) or to the right (shift = true) of the window center. Edge cases are handled by cutting the rectangular moving window at the edge.

Parameters

a

ArrayLike<number>

windowWidth

number

shift?

boolean = false

Returns

Float64Array

Clone this wiki locally