Defining a white noise process in Python
Solution 1
You can achieve this through the numpy.random.normal
function, which draws a given number of samples from a Gaussian distribution.
import numpy
import matplotlib.pyplot as plt
mean = 0
std = 1
num_samples = 1000
samples = numpy.random.normal(mean, std, size=num_samples)
plt.plot(samples)
plt.show()
Solution 2
Short answer is numpy.random.random()
. Numpy site description
But since I find more and more answers to similar questions written as numpy.random.normal
, I suspect a little description is needed. If I do understand Wikipedia (and a few lessons at the University) correctly, Gauss and White Noise are two separate things. White noise has Uniform distribution, not Normal (Gaussian).
import numpy.random as nprnd
import matplotlib.pyplot as plt
num_samples = 10000
num_bins = 200
samples = numpy.random.random(size=num_samples)
plt.hist(samples, num_bins)
plt.show()
This is my first answer, so if you correct mistakes possibly made by me here, I'll gladly update it. Thanks =)
Related videos on Youtube
abcd
Updated on January 09, 2020Comments
-
abcd over 4 years
I need to draw samples from a white noise process in order to implement a particular integral numerically.
How do I generate this with Python (i.e., numpy, scipy, etc.)?
-
papahabla about 8 years
numpy.random.standard_normal(size=num_samples)
can also be used when mean=0, and std=1 -
Gluttton over 6 years
White noise has Uniform distribution, not Normal (Gaussian).
White noise must have Uniform distribution over frequencies but it can have any distribution over time (for instance Normal). -
ivangtorre almost 6 yearsAs Wikipedia says: " white noise is a random signal having equal intensity at different frequencies". This means that you can have any kind of PDF for the signal as long as there are no temporary correlations. So White noise can have Uniform distribution, Normal distribution or other kind of distributions
-
ivangtorre almost 6 yearsYou can achieve this with any kind of distribution as long as there are no autocorrelations in the signal. "numpy.random.uniform(low=0.0, high=1.0, size=1000)", "np.random.triangular(-3, 0, 8, 100000)" will also get white noise. You can also have a correlated signal process and randomize it using "numpy.random.shuffle" for getting white noise.
-
Vortico almost 6 yearsThis answer is incorrect. White noise is a continuous process from any uncorrelated random process, like uniform or normal. However, if you digitize it, you must apply a bandpass filter at the Nyquist frequency, otherwise your approximation of the continuous process contains aliasing. It turns out that bandpassing white noise results in a discrete random process where each sample is picked from a Gaussian/normal distribution. This is the result of your confusion. Gaussian and white noise are the same thing in discrete processes. Gaussian is a subset of continuous white noise processes.
-
bluenote10 over 3 years@Vortico Interesting comment! In an attempt to understand what you are saying I have opened a follow up question :).
-
Alex Monras almost 2 yearsthis is not white noise