| Simulink Reference | ![]() |
Implement a weighted moving average
Library
Description
The Weighted Moving Average block samples and holds the N most recent inputs, multiplies each input by a specified value (given by the Weights parameter), and stacks them in a vector. This block supports both single-input/single-output (SISO) and single-input/multi-output (SIMO) modes.
For the SISO mode, the Weights parameter is specified as a row vector. For the SIMO mode, the weights are specified as a matrix where each row corresponds to a separate output.
The Initial condition parameter provides the initial values for all times preceding the start time. You specify the time interval between samples with the Sample time parameter.
You can choose whether or not to specify the data type and scaling of the weights in the dialog with the Gain data type and scaling parameter. If you select Specify via dialog for this parameter, the Parameter data type, Parameter scaling, and Parameter scaling mode parameters become visible.
You can specify the scaling for the weights with the Parameter scaling and Parameter scaling mode parameters. If Parameter data type is a generalized fixed-point number such as sfix(16), the Parameter scaling mode list provides you with these scaling modes:
Use Specified Scaling--This mode uses the [Slope Bias] or binary point-only scaling specified by the Parameter scaling parameter (for example, 2^-10).
Best Precision: Element-wise--This mode produces binary points such that the precision is maximized for each element of the Weights parameter.
Best Precision: Row-wise--This mode produces a common binary point for each element of the Weights row based on the best precision for the largest value of that row.
Best Precision: Column-wise--This mode produces a common binary point for each element of the Weights column based on the best precision for the largest value of that column.
Best Precision: Matrix-wise--This mode produces a common binary point for each element of the Weights matrix based on the best precision for the largest value of the matrix.
If the weights are specified as a row vector, then scaling element-wise and column-wise produce the same result, while scaling matrix-wise and row-wise produce the same result.
The Weighted Moving Average block first multiplies its inputs by the Weights parameter, converts those results to the output data type using the specified rounding and overflow modes, and then carries out the summation.
Data Type Support
The Weighted Moving Average block supports all data types supported by Simulink, including fixed-point data types.
Parameters and Dialog Box
The Main pane of the Weighted Moving Average block dialog appears as follows:
-1. See Specifying Sample Time in the online documentation for more information.
The Parameter data types pane of the Weighted Moving Average block dialog appears as follows:
Specify via dialog, the Parameter data type, Parameter scaling, and Parameter scaling mode parameters become visible.
Specify via dialog for the Gain data type and scaling parameter.
Specify via dialog for the Gain data type and scaling parameter.
Specify via dialog for the Gain data type and scaling parameter.
The Signal data types pane of the Weighted Moving Average block dialog appears as follows:
Examples
Suppose you want to configure this block for two outputs (SIMO mode) where the first output is given by
and the initial values of u(k - 1) and u(k - 2) are given by ic1 and ic2, respectively. To configure the Weighted Moving Average block for this situation, you must specify the Weights parameter as [a1 b1 c1; a2 b2 c2] where c2 = 0, and the Initial condition parameter as [ic1 ic2].
Characteristics
| Direct Feedthrough |
Yes |
| Scalar Expansion |
Yes, of initial conditions |
| Variable Transport Delay | Weighted Sample Time | ![]() |
© 1994-2005 The MathWorks, Inc.