# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English version of the page.

# Moving Average

Moving average

• Library:
• DSP System Toolbox / Statistics

## Description

The Moving Average block computes the moving average of the input signal along each channel independently over time. The block uses either the sliding window method or the exponential weighting method to compute the moving average. In the sliding window method, a window of specified length moves over the data sample by sample, and the block computes the average is over the data in the window. In the exponential weighting method, the block multiplies the data samples with a set of weighting factors and then sums the weighted data to compute the average. For more details on these methods, see Algorithms.

## Ports

### Input

expand all

Data over which the block computes the moving average. The block accepts real-valued or complex-valued multichannel inputs, that is, m-by-n size inputs, where m ≥ 1 and n ≥ 1. The block also accepts variable-size inputs. During simulation, you can change the size of each input channel. However, the number of channels cannot change.

Data Types: `single` | `double`
Complex Number Support: Yes

### Output

expand all

The size of the moving average output matches the size of the input. The block uses either the sliding window method or the exponential weighting method to compute the moving average. For more details, see Algorithms.

Data Types: `single` | `double`
Complex Number Support: Yes

## Parameters

expand all

• `Sliding window` — A window of length Window length moves over the input data along each channel. For every sample the window moves by, the block computes the average over the data in the window.

• `Exponential weighting` — The block multiplies the samples by a set of weighting factors. The magnitude of the weighting factors decreases exponentially as the age of the data increases, never reaching zero. To compute the average, the algorithm sums the weighted data.

When you select this check box, the length of the sliding window is equal to the value you specify in . When you clear this check box, the length of the sliding window is infinite. In this mode, the block computes the average of the current sample and all previous samples in the channel.

Window length specifies the length of the sliding window. This parameter appears when you select the check box.

This parameter applies when you set Method to ```Exponential weighting```. A forgetting factor of 0.9 gives more weight to the older data than does a forgetting factor of 0.1. A forgetting factor of 1.0 indicates infinite memory. All previous samples are given an equal weight.

This parameter is tunable. You can change its value even during the simulation.

• `Code generation`

Simulate model using generated C code. The first time you run a simulation, Simulink® generates C code for the block. The C code is reused for subsequent simulations, as long as the model does not change. This option requires additional startup time but provides faster simulation speed than `Interpreted execution`.

• `Interpreted execution`

Simulate model using the MATLAB®  interpreter. This option shortens startup time but has slower simulation speed than ```Code generation```.

expand all

Watch now