Main Content

rms

Root-mean-square value

Description

example

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

  • Ifxis a row or column vector, thenyis a real-valued scalar.

  • Ifxis a matrix, thenyis a row vector containing the RMS value for each column.

  • Ifxis a multidimensional array, thenycontains the RMS values computed along the first array dimension of size greater than 1. The size of this dimension is1while the sizes of all other dimensions remain the same asx.

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

example

y= rms(x,dim)operates along the dimensiondim. For example, ifxis a matrix, thenrms(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 vectorvecdim. For example, ifxis a matrix, thenrms(x,[1 2])operates on all the elements ofxbecause every element of a matrix is contained in the array slice defined by dimensions 1 and 2.

example

y= rms(___,nanflag)wherenanflagis"omitnan", ignores theNaNvalues in the calculation. The default fornanflagis"includenan", which includes theNaNvalues. Use this option with any of the previous syntaxes.

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×35.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×112.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 vector and compute the RMS value, excludingNaNvalues by specifying the"omitnan"option.

x = [1.77 -0.005 3.98 -2.95 NaN 0.34 NaN 0.19]; y = rms(x,"omitnan")
y = 2.1536

If you do not specify "omitnan", thenrmsreturnsNaN.

Input Arguments

collapse all

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

Data Types:single||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 of size greater than 1.

Dimensiondimindicates the dimension whose length reduces to1. Thesize(y,dim)is1, while the sizes of all other dimensions remain the same asx.

Consider anm-by-ninput matrix,x:

  • y = rms(x,1)computes the RMS value of the elements in each column ofxand returns a1-by-nrow vector.

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

Vector of dimensions, specified as a vector of positive integers. Each element represents a dimension of the input array. The lengths of the output in the specified operating dimensions are 1, while the others remain the same.

For example, ifxis a 2-by-3-by-3 array, thenrms(x,[1 2])returns a 1-by-1-by-3 array whose elements are the RMS values over each page ofx.

NaNcondition, specified as one of these values:

  • "includenan"— IncludeNaNvalues when computing the RMS values, resulting inNaN.

  • "omitnan"— Ignore allNaNvalues in the input. If all elements areNaN, the result isNaN.

Output Arguments

collapse all

Root-mean-square value, returned as a scalar, vector, orN-D array.

  • Ifxis a row or column vector, thenyis a scalar.

  • Ifxis a matrix, thenyis a vector containing the RMS values computed along dimensiondimor dimensionsvecdim.

  • Ifxis a multidimensional array, thenycontains the RMS values computed along the dimensiondimor dimensionsvecdim. The size of this dimension is1while the sizes of all other dimensions remain the same asx.

More About

collapse all

Root-Mean-Square Value

The root-mean-square value of a vectorxis

x RMS = 1 N n = 1 N | x n | 2 ,

with the summation performed along the specified dimension.

Extended Capabilities

Version History

Introduced in R2012a

expand all

Behavior changed in R2022a

See Also

|||||(Signal Processing Toolbox)