Main Content

Moving Average

Moving average-value computation

  • Moving Average block

Simscape / Electrical / Control / General Control


The Moving Average block computes the moving average value of the input signal. Use this block to filter higher frequency signal components and to smooth noisy signals.


The moving average is computed based on a moving time window. The moving average for continuous-time is calculated as



  • u(t) is the input signal,

  • 1f

  • f is the fundamental frequency of the signal.

The moving average for discrete-time is calculated as:



If you use this block for continuous-time operations and set the Sample time (-1 for inherited) parameter to 0, you should also specify the value of the Buffer size parameter to ensure it covers the moving time window.


  • The output is initialized with the initial condition in the time interval [0, T0]



expand all

Input signal.

Data Types: single | double


expand all

Moving average of the input signal.

Data Types: single | double


expand all

Fundamental frequency of the signal, in Hz. If you specify the fundamental frequency using a vector, it must match the input vector dimension.

The initial value of the input signal.

Size of the buffer.


To enable this parameter, set Sample time (-1 for inherited) to 0.

Time between consecutive block executions. During execution, the block produces outputs and, if appropriate, updates its internal state. For more information, see What Is Sample Time? and Specify Sample Time.

For inherited discrete-time operation, set this parameter to -1. For discrete-time operation, set this parameter to a positive integer. For continuous-time operation, set this parameter to 0.

If this block is in a masked subsystem or a variant subsystem that supports switching between continuous operation and discrete operation, promote this parameter to ensure correct switching between the continuous and discrete implementations of the block. For more information, see Promote Block Parameters on a Mask.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2018b