Moving RMS
R2026bMoving root mean square (RMS)
Moving RMS block
To add a block to a model, double-click the canvas and start typing the block name. Then, select the block from the list.
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
Compute Moving RMS of Noisy Step Signal
Compute moving RMS using both the sliding window method and the exponential weighting method.
Ports
Input
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
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 Signal | Input Dimensions | Output Dimensions When Allow arbitrary frame length for fixed-size input signals Appears | Output Dimensions When Allow arbitrary frame length for fixed-size input signals Does Not Appear |
|---|---|---|---|
| Fixed-size signal | m-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 signal | m-by-n, where m is not a multiple of the hop size (window length − overlap length) |
If you do not select Allow arbitrary frame length for fixed-size input signals, the block errors. | m-by-n |
| Variable-size signal | m-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
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 length−Overlap 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 |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Algorithms
In the sliding window method, the output for each input sample is the RMS of the current sample and Len – 1 previous samples. Len is the length of the window in samples. To compute the first output sample, the algorithm waits until it receives the hop size number of input samples. Hop size is defined as window length – overlap length. Remaining samples in the window are considered to be zero. As an example, if the window length is 5 and the overlap length is 2, then the algorithm waits until it receives 3 samples of input to compute the first sample of the output. After generating the first output, it generates the subsequent output samples for every hop size number of input samples.
When you do not specify the window length, the algorithm chooses an infinite window length. In this mode, the output is the moving RMS of the current sample and all the previous samples in the channel.
Consider an example of computing the moving RMS of a streaming input data using the sliding window method. The algorithm uses a window length of 4 and an overlap length of 3. With each input sample that comes in, the window of length 4 moves along the data.
![Sliding window method for moving RMS with window length 4 and input samples [–1, –2, 3, 2, 5, 2]. At each time step n=0 through n=5, the window fills with zeros until length 4 is reached, then moves along the data. Moving RMS computes rms for each window position, producing values 0.5, 1.118, 1.871, 2.121, 3.24, 3.24 at n=5](movrms_slidewin.png)
In the exponential weighting method, the moving RMS is computed recursively using these formulas:
— Moving RMS at the current sample
— Square of the current input data sample
— Moving RMS at the previous sample
λ — Forgetting factor
— Weighting factor applied to the current data sample
— Effect of the previous data on the RMS
For the first sample, where N = 1, the algorithm chooses = 1. For the next sample, the weighting factor is updated and used to compute the RMS, as per the recursive equation. As the age of the data increases, the magnitude of the weighting factor decreases exponentially and never reaches zero. In other words, the recent data has more influence on the current RMS than the older data.
The value of the forgetting factor determines the rate of change of the weighting factors. 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 the previous samples are given an equal weight.
Here is an example of computing the moving RMS using the exponential weighting method. The forgetting factor is 0.9.
![Exponential weighting method for moving RMS with forgetting factor 0.9. Three input frames: [2,3,4,5] at n=0 producing outputs [2.000, 2.575, 3.176, 3.798], [6,7,8,9] at n=1 producing outputs [4.437, 5.093, 5.765, 6.451], and [3,4,6,8] at n=2 producing outputs [6.025, 5.761, 5.796, 6.151]](movrms_expwei.png)
When you specify the window length to be tunable, the moving RMS algorithm maintains an internal buffer of size MaxWL−1 to store past input samples, where MaxWL is the maximum window length. At each time step, the moving RMS algorithm performs these operations:
Concatenates the buffer with the current input to form an extended data sequence.
Extracts the most recent window length samples from the extended data sequence.
Computes the moving RMS over the extracted samples using a sliding window and discards the endpoints.
Stores the most recent MaxWL−1 samples in the buffer for the next time step.
This approach allows you to change the window length at each time step while the algorithm maintains continuity of the output signal.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Version History
Introduced in R2016bYou can now 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 WL input port by selecting Specify window length from input port. The Maximum window length parameter sets the upper bound for the tunable window length. Select Auto-adjust invalid window length to control whether invalid window length values are automatically adjusted with a warning or cause an error.
You can now specify a forgetting factor of 0 in the Moving RMS block.
The default value of the Simulate using parameter is now
Interpreted execution. With this change, the block uses the
MATLAB interpreter for simulation by default.
Starting in R2022b, you can specify the overlap length between sliding windows using the Overlap length parameter.
The Moving RMS block supports input signals with arbitrary frame lengths when the:
Input signal is a fixed-size signal (frame length does not change during simulation) and you select the Allow arbitrary frame length for fixed-size input signals parameter (if enabled).
Input signal is a variable-size signal (frame length changes during simulation).
When this block supports an arbitrary frame length input signal, the input frame length does not have to be a multiple of the hop size.
See Also
Blocks
- RMS | Moving Average | Moving Maximum | Moving Minimum | Moving Standard Deviation | Moving Variance | Median Filter
Objects
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
