GithubHelp home page GithubHelp logo

felixpatzelt / colorednoise Goto Github PK

View Code? Open in Web Editor NEW
183.0 183.0 19.0 2.54 MB

Python package to generate Gaussian (1/f)**beta noise (e.g. pink noise)

License: MIT License

Python 100.00%
correlations noise-generator power-laws python python2 python3 time-series

colorednoise's People

Contributors

atspaeth avatar charlesbmi avatar felixpatzelt avatar onnoeberhard avatar ruabraun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

colorednoise's Issues

Using different sampling frequencies

Hi, and thanks for making this available.

I'm not sure if this is more of a feature request or just a question/lack of understanding on how to use the script from my part. I need to generate pink noise but with a sampling frequency of 20Hz instead of 1. If I just generate a big signal and sample it at different frequencies, the behaviour I get is quite different.

To illustrate, see the two attached figures, where I used the same random seed and generated both pink and brown noise for 30s, but sampled at 1Hz vs 100Hz. I would have expected a similar version of the signals in both cases, just better "interpolated". Instead, I see much more variance in the 100Hz case.

To fix(?) this, I thought it would be enough to simply adapt the frequency generation in line 68 of the script, as such f = rfftfreq(samples, 1/fs), but this seemed to make no difference. Could you point me on how to get the expected behaviour? Happy to do changes and submit a pull request if appropriate.

Figure_1Hz
Figure_100Hz

Checking by frequency

Hi!

Just trying to generate pink noise using this package. I am not familiar with knowledge of color noise. However, according to Wikipedia, it seems that the pink noise will show obvious pattern when the x-axis is frequency and the y-axis is power.

Do you have such module that I can generate a numpy-array with this frequency-power format? Or any ways that I can check if the generated plots obey the distribution?

Thanks a lot!

Brown noise looks different with different sample length

Hi,

If I generate a brownian noise with 16000 sample points using your library (something like y = powerlaw_psd_gaussian(2.0, 16000)), and save it with a sample rate of 16000, its fft spectrum looks as follows:

no title

If I generate the same noise with 16000000 samples and save it using the same sample rate as before (16000), the fft spectrum looks like:

no title1

As you can see, the spectrum looks quite different, and they actually sound very different. Is there anything wrong with my way of using your code? Also, as you can see in the second figure, there is a drastic drop in the wave plot near the end of the wave. It seems the wave drop to a very low value and comes back immediately in the point after. Is this normal?

Thanks for the help!

Make colorednoise citeable

Hi,

Thanks for this great little module. I am using it quite a bit in my academic work, and would love to cite it but there isn't any way to do so (at least not in a way that is useful / pushes up your h-index). Since its download statistics are pretty solid, I suspect that I am not the only one. May I suggest that you submit a brief write-up to a citeable institution? I have had good experiences with the Journal of Open Source Science with one of my own projects (otherwise not affiliated in any way).

All the best,
Paul

PS: I just saw on your Google Scholar profile that you used to work with Klaus Pawelzik. For two years, Klaus spent most of holidays teaching me and a bunch of other kids computational neuroscience. Small world.

'ZeroDivisionError: float division by zero' occuring when generating any noise

The code I am trying to run should print out a histogram that proves central limit theorem that when you sum of several noise sources of different distributions you get a normal distribution

import colorednoise as cnoise

noises = []
for i in range(100):
    noise = 0
    for n in range(3):
        noise = noise + cnoise.powerlaw_psd_gaussian(1,n) # order of the noise = n (n=0:white, n=1:pink, n=2:brown)
    noises.append(noise)

plt.hist(noises)

However I'm getting the following error:

---------------------------------------------------------------------------
ZeroDivisionError                         Traceback (most recent call last)
Cell In[43], line 7
      5     noise = 0
      6     for n in range(3):
----> 7         noise = noise + cnoise.powerlaw_psd_gaussian(1,n) # order of the noise = n (n=0:white, n=1:pink, n=2:brown)
      8     noises.append(noise)
     10 plt.hist(noises)

File [c:\Users\.\AppData\Local\anaconda3\lib\site-packages\colorednoise.py:81](file:///C:/Users/./AppData/Local/anaconda3/lib/site-packages/colorednoise.py:81), in powerlaw_psd_gaussian(exponent, size, fmin, random_state)
     77 samples = size[-1]
     79 # Calculate Frequencies (we asume a sample rate of one)
     80 # Use fft functions for real output (-> hermitian spectrum)
---> 81 f = rfftfreq(samples)
     83 # Validate / normalise fmin
     84 if 0 <= fmin <= 0.5:

File [c:\Users\.\AppData\Local\anaconda3\lib\site-packages\numpy\fft\helper.py:218](file:///C:/Users/./AppData/Local/anaconda3/lib/site-packages/numpy/fft/helper.py:218), in rfftfreq(n, d)
    216 if not isinstance(n, integer_types):

I'm running python 3.10.9 and have used ```pip install colorednoise``` to install
    217     raise ValueError("n should be an integer")
--> 218 val = 1.0/(n*d)
    219 N = n//2 + 1
    220 results = arange(0, N, dtype=int)

ZeroDivisionError: float division by zero

Seems like a problem in the core algorithm somewhere. Thoughts?

I'm using python 3.10.9. Installed using pip install colorednoise

Fmin > 0.5 causes divide by 0 when exponent is positive

This may be a lack of understanding of the underlying mechanics on my part, but I am getting back NaN and inf filled Arrays when setting fmin to any value > 0.5 when the exponent is positive. For white noise it doesn't cause NaN/inf, and a seemingly normal array is returned, by a FFT on the signal shows that frequencies below the minimum still appear to be present.

Some examples of calls that will replicate
powerlaw_psd_gaussian(2, 16000, fmin=100)
powerlaw_psd_gaussian(1, 16000, fmin=5)
powerlaw_psd_gaussian(0.1, 16000, fmin=1000)

Examples of calls that will not cause error, but don't appear to remove the minimum frequency.
powerlaw_psd_gaussian(0, 16000, fmin=100)
powerlaw_psd_gaussian(-1, 16000, fmin=5000)

Please let me know if any additional info is needed. Thank you!

2D colored noise?

Hello there,

First of all thanks for the amazing library. I have a usecase where I need 2D colored noise. I suspect that simply generating a long array and resize it into a 2D matrix is not what I want as the power spectra on the second axis may not be correct. Curious if you have any suggestion on this?

Thanks a lot,
Yu

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.