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.)?

up vote 8 down vote accepted

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()

1000 random samples drawn from a Gaussian distribution of mean=0, std=1

  • 1
    numpy.random.standard_normal(size=num_samples) can also be used when mean=0, and std=1 – papahabla Mar 4 '16 at 0:29
  • You 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. – ivangtorre May 9 at 9:54

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()

Image: Result

This is my first answer, so if you correct mistakes possibly made by me here, I'll gladly update it. Thanks =)

  • 1
    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). – Gluttton Dec 26 '17 at 10:42
  • As 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 May 9 at 9:46

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.