Moving Root Mean Square
the moving Root Mean Square (RMS) of the input signal along each channel,
independently over time. The object 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 is moved
over the data, sample by sample, and the RMS is computed over the
data in the window. In the exponential weighting method, the object
squares the data samples, multiplies them with a set of weighting
factors, and sums the weighed data. The object then computes the RMS
by taking the square root of the sum. For more details on these methods,
The object accepts multichannel inputs, that is, m-by-n size inputs, where m ≥ 1, and n > 1. The object also accepts variable-size inputs. Once the object is locked, you can change the size of each input channel. However, the number of channels cannot change. This object supports C and C++ code generation.
To compute the moving RMS of the input:
dsp.MovingRMS object and
set the properties of the object.
step to compute the moving RMS.
Alternatively, instead of using the
to perform the operation defined by the System
object, you can
call the object with arguments, as if it were a function. For example,
= step(obj,x) and
y = obj(x) perform
movRMS = dsp.MovingRMS returns a moving
movRMS, using the default properties.
movRMS = dsp.MovingRMS(Len) sets the
movRMS = dsp.MovingRMS(Name,Value) specifies
additional properties using
Name,Value pairs. Unspecified
properties have default values.
movRMS = dsp.MovingRMS('Method','Exponential weighting','ForgettingFactor',0.9);
Method— Moving RMS method
'Sliding window'(default) |
Moving RMS method, specified as
'Sliding window' or
'Sliding window' — A window
of length specified by
moved over the input data along each channel. For every sample the
window moves by, the object computes the RMS over the data in the
'Exponential weighting' —
The object multiplies the squares of the samples with 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 RMS, the algorithm sums the weighted data, and takes a square
root of the sum.
For more details on these methods, see Algorithms.
SpecifyWindowLength— Specify window length
Flag to specify a window length, specified as a scalar Boolean.
true — The length of
the sliding window is equal to the value you specify in the
false — The length of
the sliding window is infinite. In this mode, the RMS is computed
using the current sample and all past samples.
This property applies when you set
WindowLength— Length of the sliding window
Length of the sliding window, specified as a positive scalar
integer. This property applies when you set
ForgettingFactor— Exponential weighting factor
Exponential weighting factor, specified as a positive real scalar
in the range (0,1]. This property applies when you set
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 past samples are given an equal weight.
This property is tunable. You can change its value even when the object is locked.
|reset||Reset internal states of System object|
|step||Moving RMS of input signal|
Compute the moving RMS of a noisy square wave signal with varying amplitude using the
movrmsWin uses the sliding window method with a window length of 20.
movrmsExp uses the exponential weighting method with a forgetting factor of 0.995. Create a time scope for viewing the output.
FrameLength = 10; Fs = 100; movrmsWin = dsp.MovingRMS(20); movrmsExp = dsp.MovingRMS('Method','Exponential weighting',... 'ForgettingFactor',0.995); scope = dsp.TimeScope('SampleRate',Fs,... 'TimeSpanOverrunAction','Scroll',... 'TimeSpan',100,... 'ShowGrid',true,... 'YLimits',[-1.0 5.5]); title = 'Sliding Window RMS (blue) and Exponentially Weighted RMS (red)'; scope.Title = title;
Compute the RMS
Generate a noisy square wave signal. Vary the amplitude of the square wave after a given number of frames. Apply the sliding window method and the exponential weighting method on this signal. View the output on the time scope.
count = 1; Vect = [1/8 1/2 1 2 3 4]; index = 1; for index = 1:length(Vect) V = Vect(index); for i = 1:160 x = V + 0.1 * randn(FrameLength,1); y1 = movrmsWin(x); y2 = movrmsExp(x); scope([x,y1,y2]); end end
In the sliding window method, the output for each input sample is the RMS of the current sample and the Len - 1 previous samples. Len is the length of the window. To compute the first Len - 1 outputs, when the window does not have enough data yet, the algorithm fills the window with zeros. As an example, to compute the RMS when the second input sample comes in, the algorithm fills the window with Len - 2 zeros. The data vector, x, is then the two data samples followed by Len - 2 zeros.
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. With each input sample that comes in, the window of length 4 moves along the data.
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.
 Bodenham, Dean. “Adaptive Filtering and Change Detection for Streaming Data.” PH.D. Thesis. Imperial College, London, 2012.
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).