Voss 1/f noise algo help
gbreed at cix.compulink.co.uk
gbreed at cix.compulink.co.uk
Fri Mar 8 06:44:56 EST 2002
kevin parks wrote:
> Hi I have a couple of attempts below at the beginnings of a 1/f^2
> Noise generator. It is in a sort of heavily commented psuedo Python
> (somewhat translated from PASCAL) You can see that there are some
> areas where i am in way over my head. I may have introduced a mistake
> or two as well. Anyone familiar with Voss's algorithym want to help
> smooth out the rough edges here? It sure would be nice to be able to
> generate pink noise values in Python (brownian noise would be good
> too, I am trying to work something up on that too).
I'm not familiar with this Voss algorithm, but I did write code to
generate fractional noise in C++ a while back. It can be a lot simpler
than what you're writing. Here's the important function, converted into
pseudo-Python:
def fractionalNoise(beta, nPoints)
"""return noise with frequency spectrum 1/f**beta or something"""
randomGenerator = Gauss()
# initialize in the frequency domain
data = []
for i in range(nPoints):
amplitude = ((i+1)**(-0.5*beta))*gauss()
phase = 2*math.pi*rand()
data.append((amplitude*math.cos(phase), amplidude*math.sin(phase)))
return FFT(data)
You need three magic functions:
gauss() returns a random number according to a Gaussian distribution with
a standard deviation of 1. random.gauss looks suspiciously relevant
rand() is the usual random number between 0 and 1. Must be possible.
FFT() is a fast fourier transform. There should be one in either Numeric
or Scientific Python. I'm not sure exactly what the result means, but
both real and complex parts sound like noise.
I think the standard libary includes routines for writing .wav files.
Happy hunting!
Graham
<http://www.microtonal.co.uk/>
More information about the Python-list
mailing list