felixpatzelt / colorednoise

Python package to generate Gaussian (1/f)**beta noise (e.g. pink noise)
MIT License
195 stars 20 forks source link

Vectorise #3

Closed felixpatzelt closed 5 years ago

felixpatzelt commented 5 years ago

Separate branch to add tests, maximise readability, and fix minor bugs in @atspaeth 's original implementation of the vectorisation.

atspaeth commented 5 years ago

You don't have a conjugate-symmetric spectrum, so the component with frequency 0.5 is truncated, which means that the real part of the output of the IFFT has too little variance in the even case. The effect is most visible for small even-length sequences of white noise: cn.powerlaw_psd_gaussian(0, (10**5,10)).var(axis=1).mean() is about 0.85, while if you replace 10 with 11, it works fine.

Re: the bug you found in the other PR, my fix worked and is pushed to my fork.

felixpatzelt commented 5 years ago

Thanks, the 0.5 frequency fix somehow got lost. I tried to clean everything up a bit to make the code as understandable as possible (by my subjective standard), so it is easier to see if everything is correct. I also added another test specifically for very small sample odd and even sample sizes. PS: I combined my changes into a single commit to clutter up the master branch a bit less. I don't want to squash merge to keep external contributions visible.

felixpatzelt commented 5 years ago

Looks all good to me now, will merge in a few days if no new issues come up.

atspaeth commented 5 years ago

Yeah, it looks good! I haven't had a chance to test it much yet, but it's much cleaner now and looks correct.