You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate Gaussian distributed noise with a power law spectrum with arbitrary
exponents.
An exponent of two corresponds to brownian noise. Smaller exponents
yield long-range correlations, i.e. pink noise for an exponent of 1 (also
called 1/f noise or flicker noise).
Based on the algorithm in:
Timmer, J. and Koenig, M.:
On generating power law noise.
Astron. Astrophys. 300, 707-710 (1995)
Older Python 3 versions were not tested, but are likely to work.
For Python 2 please use colorednoise version 1.x.
Examples
importcolorednoiseascnbeta=1# the exponentsamples=2**18# number of samples to generatey=cn.powerlaw_psd_gaussian(beta, samples)
# optionally plot the Power Spectral Density with Matplotlib#from matplotlib import mlab#from matplotlib import pylab as plt#s, f = mlab.psd(y, NFFT=2**13)#plt.loglog(f,s)#plt.grid(True)#plt.show()
# generate several time series of independent indentically distributed variables# repeat the simulation of each variable multiple timesimportcolorednoiseascnn_repeats=10# repeat simulatonsn_variables=5# independent variables in each simulationtimesteps=1000# number of timesteps for each variabley=cn.powerlaw_psd_gaussian(1, (n_repeats, n_variables, timesteps))
# the expected variance of for each variable is 1, but each realisation is differentprint(y.std(axis=-1))
# generate a broken power law spectrum: white below a frequency ofimportcolorednoiseascny=cn.powerlaw_psd_gaussian(1, 10**5, fmin=.05)
s, f=mlab.psd(y, NFFT=2**9)
#plt.loglog(f,s)#plt.grid(True)#plt.show()
About
Python package to generate Gaussian (1/f)**beta noise (e.g. pink noise)