Main Content

rms

Root mean square value

Description

y = rms(x) returns the root mean square (RMS) value of the input, x.

  • If x is a row or column vector, then y is a real-valued scalar.

  • If x is a matrix, then y is a row vector containing the RMS value for each column.

  • If x is a multidimensional array, then y contains the RMS values computed along the first array dimension whose size does not equal 1. The size of y in this dimension is 1, while the sizes of all other dimensions remain the same as in x.

example

y = rms(x,"all") returns the RMS value of all elements in x.

y = rms(x,dim) operates along dimension dim. For example, if x is a matrix, then rms(x,2) operates on the elements in each row and returns a column vector containing the RMS value of each row..

example

y = rms(x,vecdim) operates along the dimensions specified in the vector vecdim. For example, if x is a matrix, then rms(x,[1 2]) operates on all the elements of x because every element of a matrix is contained in the array slice defined by dimensions 1 and 2.

example

y = rms(___,nanflag) specifies whether to include or omit NaN values in the calculation for any of the previous syntaxes. For example, rms(x,"omitnan") ignores NaN values when computing the RMS. By default, rms includes NaN values.

example

Examples

collapse all

Compute the RMS value of a sinusoid.

t = 0:0.001:1-0.001;
x = cos(2*pi*100*t);
y = rms(x)
y = 
0.7071

Create a matrix and compute the RMS value of each column.

x = [4 -5 1; 2 3 5; -9 1 7];
y = rms(x)
y = 1×3

    5.8023    3.4157    5.0000

Create a matrix and compute the RMS value of each row by specifying the dimension as 2.

x = [6 4 23 -3; 9 -10 4 11; 2 8 -5 1];
y = rms(x,2)
y = 3×1

   12.1450
    8.9163
    4.8477

Create a 3-D array and compute the RMS value over each page of data (rows and columns).

x(:,:,1) = [2 4; -2 1];
x(:,:,2) = [9 13; -5 7];
x(:,:,3) = [4 4; 8 -3];
y = rms(x,[1 2])
y = 
y(:,:,1) =

    2.5000


y(:,:,2) =

     9


y(:,:,3) =

    5.1235

Create a matrix containing NaN values.

x = [1.77 -0.005 NaN -2.95; NaN 0.34 NaN 0.19];

Compute the RMS values of the matrix, excluding NaN values. For matrix columns that contain any NaN value, rms computes with the non-NaN elements. For matrix columns that contain all NaN values, the RMS is NaN.

y = rms(x,"omitnan")
y = 1×4

    1.7700    0.2404       NaN    2.0903

Input Arguments

collapse all

Input array, specified as a vector, matrix, or multidimensional array.

Data Types: single | double | logical | char
Complex Number Support: Yes

Dimension to operate along, specified as a positive integer scalar. If you do not specify the dimension, then the default is the first array dimension whose size does not equal 1.

Dimension dim indicates the dimension whose length reduces to 1. The size(y,dim) is 1, while the sizes of all other dimensions remain the same as x.

Consider an m-by-n input matrix, x:

  • y = rms(x,1) computes the RMS value of the elements in each column of x and returns a 1-by-n row vector.

  • y = rms(x,2) computes the RMS value of the elements in each row of x and returns an m-by-1 column vector.

Vector of dimensions to operate along, specified as a vector of positive integers. Each element represents a dimension of the input array. The length of the output in the specified operating dimensions is 1, while the other dimension lengths remain the same as the input.

For example, if x is a 2-by-3-by-3 array, then rms(x,[1 2]) returns a 1-by-1-by-3 array whose elements are the RMS values over each page of x.

Missing value condition, specified as one of these values:

  • "includemissing" or "includenan" — Include NaN values in x when computing the RMS. If any element in the operating dimension is NaN, then the corresponding element in y is NaN. "includemissing" and "includenan" have the same behavior.

  • "omitmissing" or "omitnan" — Ignore NaN values in x when computing the RMS. If all elements in the operating dimension are NaN, then the corresponding element in y is NaN. "omitmissing" and "omitnan" have the same behavior.

More About

collapse all

Root Mean Square Value

The root mean square value of an array x is

xRMS=1Nn=1N|xn|2,

with the summation performed along the specified dimension.

Extended Capabilities

Version History

Introduced in R2012a

expand all

See Also

| | | | | (Signal Processing Toolbox)