简体   繁体   中英

How to add random noise to a signal using NumPy?

I want to add Gaussian random noise to a variable in my model for each separate time-step and not to generate a noise array and add it to my signal afterwards. In this way I want to examine a standard dynamic effect of my system.

So, I want to generate each time-step a random noise (ie a single value) and it to my signal (eg add noise then it calculates the next state, add noise it calculates the next state, etc.). I thought to do this via NumPy using the following in the dynamic section of my model over a set of time-steps:

self.x = self.x + self.a * ((d-f)/100)

self.x = self.x + np.random.normal(0, 0.5, None)`

the second line is drawing random samples from a normal distribution and adds it to my variable.

0 is the mean of the normal distribution I am choosing from, 0.5 is the standard deviation of the normal distribution and the third argument is the size.

I am wondering if numpy.random.normal is the correct way to do it and, if so, what parameter I should use for the size argument?

To generate a single number, use the 2-argument form of np.random.normal :

In [47]: np.random.normal(0, 0.5)
Out[47]: 0.6138972867165546

You may need to scale this number (multiply it by a small number epsilon ) so the noise is small compared to self.x .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM