This package is no longer maintained. Compatibility with recent versions of Python, NumPy or SciPy cannot be guaranteed.
Python power law noise generates arbitrarily long streams of power law noise using NumPy and SciPy.
The noise is generated with shaping filters and the methodology closely follows Stephane Plaszczynski, Fluct. Noise Lett. 7: R–R13, 2007. You can also find the article on arXiv:astro-ph/0510081.
pyplnoise consists of a single module providing classes implementing the following noise sources:
- general 1/fα power law noise with upper and lower frequency
limits (class
AlphaNoise
), - a fast red (Brownian) noise generator with a lower frequency limit (class
RedNoise
), - a convenience alias for pink noise (aka 1/f noise; class
PinkNoise
), - and of course white noise (class
WhiteNoise
).
The interface is very simple: just instantiate one of the above classes and run
get_sample()
to retrieve a single sample or get_series(npts)
to
retrieve an array of npts
samples. Detailed interface documentation is available in the code.
import pyplnoise
import numpy as np
fs = 10. # sampling frequency in Hz
# instantiate a noise source with lower frequency limit 1e-3 Hz,
# upper frequency limit 5 Hz and 1/f^1.5 power spectrum
noisegen = pyplnoise.AlphaNoise(fs, 1e-3, fs/2., alpha=1.5, seed=42)
one_sample = noisegen.get_sample()
many_samples = noisegen.get_series(100000)
Jupyter notebooks are provided in the /examples directory:
- Overview of the noise sources and their properties
- Application example: modeling the random signal errors of a gyroscope (Allan variance of synthetic noise)
- NumPy ≥ 1.17 (see NEP 19)
- SciPy ≥ 1.3
Installing from PyPI
pip install pyplnoise
Download the release tarball and run
python setup.py install
Because everything is contained in the module pyplnoise
, you can alternatively just copy
the module and the LICENSE file into your project.
- ...you're looking to generate 1/fα noise with very long correlation times (frequencies ≪ 10-7 Hz); particularly if your machine has limited memory resources.
- ...you like to superimpose many colored noise sources, possibly sampled at different frequencies and possessing different bandwidths.
- ...you're looking for a pink noise source for your software synthesizer or other audio stuff. There are lots of interesting solutions for such applications, notably "A New Shade of Pink", the Voss-McCartney Algorithm, which is also available in Python and some highly specialized filters.
- ...you want to generate finite 1/fα noise streams with relatively short correlation times (frequencies ≥ 10-7 Hz). In such a case Fourier transform methods are tractable and in some cases these methods deliver higher quality results than the shaping filters used by pyplnoise.