dsp.RMS

Root mean square of vector elements

Description

The dsp.RMS object computes the root mean square (RMS) value.

Note

The Running mode in the dsp.RMS System object™ will be removed in a future release. To compute the running RMS in MATLAB®, use the dsp.MovingRMS System object instead.

To compute the RMS value of your input:

  1. Create the dsp.RMS object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).

Creation

Syntax

rms = dsp.RMS
rms = dsp.RMS(Name,Value)

Description

example

rms = dsp.RMS returns a System object, rms, that computes the root mean square (RMS) of an input or a sequence of inputs over the specified Dimension.

example

rms = dsp.RMS(Name,Value) returns an RMS System object, rms, with each specified property set to the specified value.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).

Set this property to true to enable calculating the RMS over successive calls to the object algorithm.

Set this property to true to enable resetting the running RMS. When the property is set to true, you must specify a reset input to the object algorithm to reset the running RMS.

Dependencies

This property applies when you set the RunningRMS property to true.

Specify the event to reset the running RMS as one of Rising edge, Falling edge, Either edge, or Non-zero. Non-zero resets the running RMS each time a nonzero sample is acquired. See Rising and Falling Edges for definitions of rising and falling edges.

Dependencies

This property applies when you set the ResetInputPort property to true.

Specify the dimension along which to calculate the RMS as one of All, Row, Column, or Custom. Specifying the Dimension property as All computes the RMS value over the entire input.

Dependencies

This property applies only when you set the RunningRMS property to false.

Specify the dimension (one-based scalar integer value) of the input signal, along which the RMS is computed. The dimension cannot exceed the number of dimensions in the input signal.

Dependencies

This property applies when you set the Dimension property to Custom.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Usage

For versions earlier than R2016b, use the step function to run the System object algorithm. The arguments to step are the object you created, followed by the arguments shown in this section.

For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Syntax

y = rms(x)
y = rms(x,r)

Description

example

y = rms(x) computes the root mean square (RMS) output, y, of input vector x. When the RunningRMS property is true, y corresponds to the RMS of the input elements over successive calls to the object algorithm.

y = rms(x,r) resets the running RMS state based on the value of r, the reset signal, and the ResetCondition property. This computation is possible when you set both the RunningRMS and the ResetInputPort properties to true.

Input Arguments

expand all

Data input, specified as a vector or a matrix. If x is a matrix, each column is treated as an independent channel. The RMS is computed along each channel. The object also accepts variable-size inputs. Once the object is locked, you can change the size of each input channel.

Data Types: single | double
Complex Number Support: Yes

Reset signal used to reset the running RMS, specified as a scalar value. The object resets the running RMS if the reset signal satisfies the ResetCondition.

Dependencies

To enable this signal, set the RunningRMS property to true and the ResetInputPort property to true.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Output Arguments

expand all

RMS output, returned as a scalar, vector or a matrix. If RunningRMS is set to:

  • false –– The object computes the RMS value of each input channel. If the input is a column vector, the output is a scalar. If the input is a multichannel signal, the output signal is a 1-by-N vector, where N is the number of input channels.

  • true –– The object computes the running RMS of the signal. The size of the output signal matches the size of the input signal.

Data Types: single | double
Complex Number Support: Yes

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

expand all

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For example, myObject(x) becomes step(myObject,x).

Compute the RMS value of a vector consisting of the integers 1 to 10.

x = 1:10;
rms = dsp.RMS('Dimension','row');
rmsval = rms(x)
rmsval = 6.2048

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For example, myObject(x) becomes step(myObject,x).

Compute the RMS value of a matrix with the Dimension property set to 'All'.

in2 = magic(4);
rms2d = dsp.RMS;
rms2d.Dimension = 'All';
y_rms2 = rms2d(in2)
y_rms2 = 9.6695

The output is equivalent to reshaping the 4-by-4 matrix into a 16-by-1 or 1-by-16 vector and computing the RMS value for the vector.

More About

expand all

Algorithms

This object implements the algorithm, inputs, and outputs described on the RMS block reference page. The object properties correspond to the Simulink® block parameters, except:

  • The Treat sample-based row input as a column block parameter is not supported by the dsp.RMS object.

  • The Reset Port block parameter corresponds to both the ResetCondition and the ResetInputPort object properties.

Extended Capabilities

Introduced in R2012a