Qu

rms

Builtin index · Core maths

result = rms(x)

Input: x · Output: result

What it is

Root-mean-square, sqrt(mean(x.^2)), of every element of x — a scalar, Vec, or Mat/Signal, flattened.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = rms(x)
x scalar, Vec, Mat, or Signalnot documented yet
result scalar, Num, or vector
Returns a scalar Num. Errors on an empty vector.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

noisy = signal + 0.3 * randn(1000, seed = 1)
print("clean {rms(signal):.3f}, noisy {rms(noisy):.3f}")
output
clean 0.707, noisy 0.768

from start-here

for b in s.blocks(250)
    print(rms(b))
end for

for b in s.blocks(100 ms)      # sized against s.Fs

    print(rms(b))
end for
output
0.705691
0.70852
0.705691
0.70852
0.679771
0.76825
0.62606
0.764603
0.686392
0.679771
0.76825
0.62606
0.764603
0.686392

from signal-processing

x = sin(2 * pi * 50 * t)          # 50 Hz, one value per sample

y = x + 0.2 * randn(1000, seed = 1)   # the same signal, with noise on it

print("clean rms {rms(x):.4f}, noisy rms {rms(y):.4f}")
output
clean rms 0.7071, noisy rms 0.7375

from from-zero

lp       = butter(4, "low", 120, fs)          # 4th order, cut at 120 Hz

smoothed = filtfilt(lp, y)                    # zero-phase, forward and back

print("noise removed: rms {rms(y - x):.4f} -> {rms(smoothed - x):.4f}")
output
noise removed: rms 0.2010 -> 0.0978

from from-zero