# Moving Average (Variable Frequency)

Variable frequency moving average-value computation

Since R2020a

Libraries:
Simscape / Electrical / Control / General Control

## Description

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

### Equations

The block computes the moving average based on a moving time window. The moving average for continuous-time is equal to

`$\overline{u}=\frac{1}{{T}_{0}}\underset{{t}_{0}}{\overset{{t}_{0}+{T}_{0}}{\int }}u\left(t\right)dt,$`

where:

• u(t) is the input signal.

• T0 is equal to $\frac{1}{f}$.

• f is the fundamental frequency of the signal.

• t0 is the initial time for integration in a time window.

The moving average for discrete-time is equal to:

`$\overline{u}\left(k\right)=\frac{1}{{T}_{0}}\sum _{i=0}^{n-1}u\left(k-i\right).$`

Note

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.

### Assumptions and Limitations

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

• If you use this block for discrete-time operations and set the Sample time (-1 for inherited) parameter to `-1`, the maximum variable integer delay is set to 4096 samples. To compute the maximum variable integer delay as a function of minimum frequency and sample time, set the Sample time (-1 for inherited) parameter to a positive value.

## Ports

### Input

expand all

Moving average input, specified as a scalar or vector.

Data Types: `single` | `double`

Frequency, specified as a scalar or vector in Hz.

Data Types: `single` | `double`

### Output

expand all

Moving average of the input signal, returned as a scalar or vector.

Data Types: `single` | `double`

## Parameters

expand all

Initial frequency of the signal, in Hz. If you specify the initial frequency using a vector, it must match the dimensions of the input vector.

Minimum frequency of the signal, in Hz. If you specify the minimum frequency using a vector, it must match the dimensions of the input vector.

Initial value of the input signal.

Size of the buffer.

#### Dependencies

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.

## Version History

Introduced in R2020a