Giter VIP home page Giter VIP logo

colorednoise's Introduction

colorednoise.py

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)

Further reading: Colors of noise on Wikipedia

Installation

pip install colorednoise

Dependencies

  • Python >= 3.6.15
  • NumPy >= 1.17.0

Older Python 3 versions were not tested, but are likely to work. For Python 2 please use colorednoise version 1.x.

Examples

import colorednoise as cn
beta = 1 # the exponent
samples = 2**18 # number of samples to generate
y = 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 times
import colorednoise as cn
n_repeats   = 10   # repeat simulatons
n_variables = 5    # independent variables in each simulation
timesteps   = 1000 # number of timesteps for each variable
y = cn.powerlaw_psd_gaussian(1, (n_repeats, n_variables, timesteps))

# the expected variance of for each variable is 1, but each realisation is different
print(y.std(axis=-1))
# generate a broken power law spectrum: white below a frequency of
import colorednoise as cn
y = 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()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.