Main Content

Moving RMS

R2026b

Moving root mean square (RMS)

  • Moving RMS block

Libraries:
DSP System Toolbox / Statistics

Description

The Moving RMS block computes the moving root mean square (RMS) 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 RMS. In the sliding window method, a window of specified length moves over the data sample by sample, and the block computes the RMS over the data in the window. In the exponential weighting method, the block squares the data samples, multiplies them with a set of weighting factors, and sums the weighted data. The block then computes the RMS by taking the square root of the sum.

You can change the window length during simulation by selecting the Make window length tunable parameter. Specify the tunable window length from the block dialog box by updating the Window length parameter or through the input port WL by selecting the Specify window length from input port parameter. For more details, see Algorithms. (since R2026b)

Examples

Ports

Input

expand all

The block computes the moving RMS of the data specified at this input port. Specify real- or complex-valued multichannel inputs of the size m-by-n, where m ≥ 1 and n ≥ 1.

When the Allow arbitrary frame length for fixed-size input signals parameter appears and is not selected, and you input a fixed-size signal, the frame length must be a multiple of the hop size (window length − overlap length). In all other cases, the input frame length can be arbitrary.

The block accepts variable-size inputs (frame length changes during simulation). When you input a variable-size signal, the frame length of the signal can be arbitrary.

This port is unnamed until you enable the WL input port or the lambda input port.

Data Types: single | double
Complex Number Support: Yes

Specify the forgetting factor as a nonnegative real scalar in the range [0,1]. The forgetting factor determines how much weight the block gives to the past data. 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 and all previous samples are given an equal weight. A forgetting factor of 0 indicates no memory and the past samples have no weight on the current computation.

Dependencies

To enable this port, set Method to Exponential weighting and select Specify forgetting factor from input port.

Data Types: single | double

Since R2026b

Specify the tunable window length as a positive integer. The block uses this value as the sliding window length for computing the moving RMS.

When you select Auto-adjust invalid window length, the block adjusts invalid window length values from the input port and issues a warning. For more information on what values are invalid, see the Auto-adjust invalid window length parameter description.

When you clear the Auto-adjust invalid window length parameter, the block throws an error for invalid window length values.

Dependencies

This port appears when you set Method to Sliding window, select Specify window length, Make window length tunable, and Specify window length from input port.

Data Types: single | double

Output

expand all

Moving RMS output, returned as a vector or a matrix. The block computes the moving RMS based on the Method parameter settings using either the sliding window method or the exponential weighting method. For more details, see Algorithms.

This table provides more details on the dimensions of the output signal.

Input SignalInput DimensionsOutput Dimensions When Allow arbitrary frame length for fixed-size input signals AppearsOutput Dimensions When Allow arbitrary frame length for fixed-size input signals Does Not Appear
Fixed-size signalm-by-n, where m is a multiple of the hop size (window length − overlap length)

(m/hop size)-by-n

m-by-n

Fixed-size signalm-by-n, where m is not a multiple of the hop size (window length − overlap length)

ceil(m/hop size)-by-n when you select Allow arbitrary frame length for fixed-size input signals

If you do not select Allow arbitrary frame length for fixed-size input signals, the block errors.

m-by-n

Variable-size signalm-by-n ceil(m/hop size)-by-n

m-by-n

When the output has an upper bound size of ceil(m/hop size)-by-n, during simulation, the size of the first dimension varies in this bound and the size of the second dimension remains constant. For an example that shows this behavior, see Compute Moving RMS of Noisy Step Signal.

Data Types: single | double
Complex Number Support: Yes

Parameters

expand all

If a parameter is listed as tunable, then you can change its value during simulation.

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

  • Exponential weighting — The block multiplies the squares of the samples by a set of weighting factors. The magnitude of the weighting factors decreases exponentially as the age of the data increases, but the magnitude never reaches zero. To compute the RMS, the algorithm sums the weighted data and takes a square root of the sum.

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

Dependencies

To enable this parameter, set Method to Sliding window.

Since R2026b

Select this parameter to make the window length tunable, that is, you can change the window length during simulation through the block dialog box by updating the Window length parameter or through the input port WL by selecting Specify window length from input port.

When you clear this parameter, the window length is fixed and you cannot change it during simulation. Specify the window length through the Window length parameter.

Dependencies

To enable this parameter, set Method to Sliding window and select Specify window length.

Since R2026b

When you select this parameter, the block reads the tunable window length from the input port, WL. When you clear this parameter, the block reads the tunable window length from the Window length parameter.

Dependencies

To enable this parameter, set Method to Sliding window, select Specify window length, and select Make window length tunable.

Specify the length of the sliding window in samples as a positive integer.

When you select the Make window length tunable parameter, the window length you specify is tunable and must be less than or equal to the value you specify in the Maximum window length parameter. When you clear the Make window length tunable parameter, the window length is fixed. (since R2026b)

Dependencies

To enable this parameter, set Method to Sliding window and select Specify window length. In addition, if you select Make window length tunable, you must clear the Specify window length from input port parameter.

Specify the number of overlapped samples between sliding windows as a nonnegative integer. The value of overlap length varies in the range [0, Window length−1].

Dependencies

To enable this parameter, set Method to Sliding window, select Specify window length, and clear Make window length tunable.

Since R2026b

Specify the maximum value of the tunable window length as a positive integer. The window length you specify during simulation cannot exceed this value.

Dependencies

To enable this parameter, set Method to Sliding window, select Specify window length, and select Make window length tunable.

Since R2026b

When you select this parameter, the block adjusts invalid window length values from the input port and issues a warning.

  • If the tunable window length value is greater than Maximum window length, the block uses Maximum window length.

  • If the tunable window length value is less than 1, the block uses 1.

  • If the tunable window length value is not an integer, the block uses the floored value.

When you clear this parameter, the block throws an error for invalid window length values.

Dependencies

To enable this parameter, set Method to Sliding window, and select these parameters:

  • Specify window length

  • Make window length tunable

  • Specify window length from input port

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 hop size. Hop size is defined as Window lengthOverlap length. The block uses this parameter setting only for fixed-size input signals and ignores this parameter if the input is a variable-size signal.

When the input signal is a variable-size signal, the signal can have arbitrary frame length, that is, the frame length does not have to be a multiple of the hop size.

For fixed-size input signals, if you:

  • Select the Allow arbitrary frame length for fixed-size input signals parameter, the frame length of the signal does not have to be a multiple of the hop size. If the input is not a multiple of the hop size, then the output is generally a variable-size signal. So, to support arbitrary input size, the block must also support variable-size operations, which you can enable by selecting the Allow arbitrary frame length for fixed-size input signals parameter.

  • Clear the Allow arbitrary frame length for fixed-size input signals parameter, the input frame length must be a multiple of the hop size.

Dependencies

To enable this parameter, set Method to Sliding window, select Specify window length, and clear Make window length tunable.

When you select this parameter, the forgetting factor is input through the lambda port. When you clear this parameter, the block uses the value of the Forgetting factor parameter.

Dependencies

To enable this parameter, set Method to Exponential weighting.

Specify the exponential weighting factor as a nonnegative real scalar in the range [0,1]. This value determines how much weight to give the past data. 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 and all the past samples are given an equal weight. A forgetting factor of 0 indicates no memory and the past samples have no weight on the current computation.

Tunable: Yes

Dependencies

To enable this parameter, set Method to Exponential weighting and clear Specify forgetting factor from input port.

Specify the type of simulation to run. You can set this parameter to:

  • Interpreted execution — Simulate model using the MATLAB® interpreter. This option shortens startup time.

  • 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 subsequent simulations.

Block Characteristics

Data Types

double | single

Multidimensional Signals

No

Variable-Size Signals

Yes

Algorithms

expand all

Extended Capabilities

expand all

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

Version History

Introduced in R2016b

expand all