Block Moving Average Calculates the moving average of the input signal for each channel regardless of time.
To calculate the moving average, the block uses either the sliding window method or the exponential weighting method.
In the sliding window method, the block calculates the average value of the data in a window of a given length, which moves through the data sample.
In the exponential weighting method, the block multiplies the data samples by a set of weighting factors, and then sums the weighted data to calculate the average.
For more information about these methods, see Algorithms.
The block calculates the moving average of the data indicated on the input port. The block accepts multi-channel input data of dimension on , where and , with real or complex values.
If the check box Allow arbitrary frame length for fixed-size input signals If the input signal is shown but not set, and the input signal has a fixed size, then the frame length must be a multiple of the jump size, which is defined as the difference between the window length and the overlap length. In all other cases, the length of the input frame can be arbitrary.
The block accepts input signals of variable size (the frame length changes during the simulation process). When a variable-size signal is applied, the length of the signal frame can be arbitrary.
This port has no name yet for the parameter Method the value is not set Exponential weighting and the checkbox is not checked. Specify forgetting factor from input port.
The forgetting coefficient, given as a positive real scalar of 0 before 1, determines how much weight the past data had. At the forgetting rate 0.9 old data has more weight than with the forgetting coefficient. 0.1. The forgetting rate 1.0 means infinite memory — all previous samples have the same weight.
Dependencies
To use this port, set the parameter Method meaning Exponential weighting and check the box Specify forgetting factor from input port.
# OUT_1
—
moving average output
vector | the matrix
Details
A moving average returned as a vector or matrix. The block calculates a moving average based on the parameter settings Method using either the sliding window method or the exponential weighting method.
The table provides detailed information about the size of the output signal.
Input signal
Dimensions of the input signal
Dimensions of the output signal
The flag Allow arbitrary frame length for fixed-size input signals shown
The flag Allow arbitrary frame length for fixed-size input signals not shown
A fixed-size signal
on , where multiple of the jump size (window length is the length of the overlap)
(the size of the jump) on
on
A fixed-size signal
on , where not a multiple of the jump size (window length is the length of the overlap)
ceil(the size of the jump) on in case the check box Allow arbitrary frame length for fixed-size input signals installed. If this checkbox is unchecked, the block returns an error.
on
A variable-size signal
on
ceil(the size of the jump) on
on
When the output has an upper bound on the ceil size(the size of the jump) on during the simulation, the size of the first dimension changes within this boundary, while the size of the second dimension remains constant.
#Method —
the averaging method
Sliding window | Exponential weighting
Details
Sliding window — window length Window length moves through the input data along each channel. For each sample that the window moves through, the block calculates the average value of the data in the window.
Exponential weighting — the block multiplies the samples by a set of weighting factors. The magnitude of the weights decreases exponentially as the age of the data increases, but the magnitude never reaches zero. To calculate the average value, the algorithm summarizes the weighted data.
Values
Sliding window | Exponential weighting
Default value
Sliding window
Program usage name
Method
Tunable
No
Evaluatable
No
#Specify window length —
specify the window length
Logical
Details
If you select this option, the length of the sliding window will be equal to the value set for the parameter Window length. If you uncheck this option, the sliding window will be infinite in length. In this mode, the block calculates the average of the current sample and all previous samples in the channel.
Dependencies
To use this parameter, set for the parameter Method meaning Sliding window.
Specifies the length of the sliding window in the selections.
Dependencies
To use this parameter, set for the parameter Method meaning Sliding window and check the box Specify window length.
Default value
4
Program usage name
WindowLength
Tunable
No
Evaluatable
Yes
#Overlap length —
the length of the overlap between the windows
Int64 integer
Details
Specifies the length of the overlap between windows as a non-negative integer. The value of the overlap length varies from 0 before Window length − 1.
Dependencies
To use this parameter, set for the parameter Method meaning Sliding window and check the box Specify window length.
Default value
3
Program usage name
OverlapLength
Tunable
No
Evaluatable
Yes
#Allow arbitrary frame length for fixed-size input signals —
allow arbitrary frame length for fixed-size input signals
Logical
Details
Specify whether fixed-size input signals (whose size does not change during simulation) can have an arbitrary frame length, where the frame length does not have to be a multiple of the jump size. The size of the jump is defined as the difference in the parameter values Window length and Overlap length. The block uses this parameter only for fixed-size input signals and ignores it if the input signal has a variable size.
When the input signal has a variable size, the signal can have an arbitrary frame length, that is, the frame length should not be a multiple of the jump size.
For fixed-size input signals:
If the check box is Allow arbitrary frame length for fixed-size input signals However, the signal frame length does not have to be a multiple of the jump size. If the input signal is not a multiple of the jump size, then the output is usually a variable-size signal. Therefore, to support an arbitrary input size, the block must also support variable-size operations, which can be enabled by checking the box. Allow arbitrary frame length for fixed-size input signals.
If the check box is Allow arbitrary frame length for fixed-size input signals If the image is captured, then the length of the input frame must be a multiple of the jump size.
Dependencies
To use this parameter, set for the parameter Method meaning Sliding window and check the box Specify window length.
Default value
false (switched off)
Program usage name
AllowArbitrary
Tunable
No
Evaluatable
No
#Specify forgetting factor from input port —
specify the forgetting rate via the input port
Logical
Details
When this option is selected, the forgetting coefficient is entered via the λ port. If you uncheck this box, the forgetting coefficient is set using the parameter Forgetting factor.
Dependencies
To use this parameter, set for the parameter Method meaning Exponential weighting.
Default value
false (switched off)
Program usage name
SpecifyForgettingFactorInput
Tunable
No
Evaluatable
No
#Forgetting factor —
exponential weighting factor
Real number
Details
The forgetting coefficient determines how much weight the past data had. At the forgetting rate 0.9 old data has more weight than with the forgetting coefficient. 0.1. The forgetting rate 1.0 means infinite memory — all previous samples have the same weight.
Dependencies
To use this parameter, set for the parameter Method meaning Exponential weighting and uncheck the box Specify forgetting factor from input port.
Default value
0.9
Program usage name
ForgettingFactor
Tunable
No
Evaluatable
Yes
Algorithms
Sliding window method
Details
In the sliding window method, the output for each input sample is the average of the current sample and previous samples, where — this is the length of the window in samples. To calculate the first input sample, the algorithm waits until it receives the number of input samples of the size of a jump. The jump size is defined as the difference between the window length and the overlap length. The remaining samples in the window are considered null. For example, if the window length is 5, and the length of the overlap — 2, then the algorithm waits until it receives 3 input samples to calculate the first sample of the output signal. After generating the first output signal, it generates subsequent output samples for each number of jump-sized input samples.
If the window length is not specified, the algorithm selects an infinite window length. In this mode, the output is the moving average of the current sample and all previous samples in the channel.
Exponential weighting method
Details
In the exponential weighting method, the moving average is calculated recursively using the following formulas:
Where
— moving average of the current sample;
— current data entry selection;
— moving average of the previous sample;
— the coefficient of forgetting;
— the weighting factor applied to the current data sample;
— the influence of previous data on the average value.
For the first sample, where , the algorithm selects . For the next sample, the weighting factor is updated and used to calculate the average, according to the recursive equation. As the age of the data increases, the value of the weighting factor decreases exponentially and never reaches zero. In other words, the latest data has a greater impact on the current average than the old ones.
The forgetting coefficient determines how much weight the past data had. With the forgetting coefficient 0.9 old data has more weight than with the forgetting factor 0.1. The forgetting rate 1.0 means infinite memory — all previous samples have the same weight.