Search code examples
pythonnumpymatplotlibprobability-theory

RMS amplitude of gaussian white noise


I would like to compute the RMS Amplitude, of a gaussian white noise signal.

import matplotlib.pyplot as plt
import numpy as np

mean = 0
std = 1.0

t = 100

def zv(t):
    return np.random.normal(mean, std, size = t)

def rms(x):
    return np.sqrt(np.mean(zv(x)**2))

plt.plot(zv(t))

plt.plot(rms(t))

The plot of zv(t) works - but I don't know why the plot of rms(t) is just empty.

Do you have some comments?

Best Regards


Solution

  • zv(t) returns a one dimensional array of size t. As a result, when you take the mean, it is a single value. You can verify this by printing out the value of rms(t). If you want to create a plot along t for rms, you will need to generate multiple monte carlo samples. For example,

    def zv(t):
        n = 1000
        return np.random.normal(mean, std, size = (n, t))
    
    def rms(x):
        return np.sqrt(np.mean(zv(x)**2, axis = 0))