rms()

audmath.rms(x, *, axis=None, keepdims=False)[source]

Root mean square.

The root mean square for a signal of length NN is given by

1Nn=1Nxn2\sqrt{\frac{1}{N} \sum_{n=1}^N x_n^2}

where xnx_n is the value of a single sample of the signal.

For an empty signal 0 is returned.

Parameters
  • x (Union[int, float, Sequence, ndarray]) – input signal

  • axis (Union[int, Tuple[int], None]) – axis or axes along which the root mean squares are computed. The default is to compute the root mean square of the flattened signal

  • keepdims (bool) – if this is set to True, the axes which are reduced are left in the result as dimensions with size one

Return type

Union[floating, ndarray]

Returns

root mean square of input signal

Examples

>>> rms([])
0.0
>>> rms([0, 1])
0.7071067811865476
>>> rms([[0, 1], [0, 1]])
0.7071067811865476
>>> rms([[0, 1], [0, 1]], keepdims=True)
array([[0.70710678]])
>>> rms([[0, 1], [0, 1]], axis=1)
array([0.70710678, 0.70710678])