java.lang.Object PinkNoise
public class PinkNoise
A class that provides a source of pink noise with a power spectrum density (PSD) proportional to 1/f^alpha. "Regular" pink noise has a PSD proportional to 1/f, i.e. alpha=1. However, many natural systems may require a different PSD proportionality. The value of alpha may be from 0 to 2, inclusive. The special case alpha=0 results in white noise (directly generated random numbers) and alpha=2 results in brown noise (integrated white noise).
The values are computed by applying an IIR filter to generated Gaussian random numbers. The number of poles used in the filter may be specified. For each number of poles there is a limiting frequency below which the PSD becomes constant. Values as low as 1-3 poles produce relatively good results, however these values will be concentrated near zero. Using a larger number of poles will allow more low frequency components to be included, leading to more variation from zero. However, the sequence is stationary, that is, it will always return to zero even with a large number of poles.
The distribution of values is very close to Gaussian with mean
zero, but the variance depends on the number of poles used. The
algorithm can be made faster by changing the method call
rnd.nextGaussian()
to
rnd.nextDouble()-0.5
in the method nextValue()
. The resulting distribution is
almost Gaussian, but has a relatively larger amount of large
values.
The IIR filter used by this class is presented by N. Jeremy Kasdin, Proceedings of the IEEE, Vol. 83, No. 5, May 1995, p. 822.
Constructor Summary | |
---|---|
PinkNoise()
Generate pink noise with alpha=1.0 using a five-pole IIR. |
|
PinkNoise(double alpha)
Generate a specific pink noise using a five-pole IIR. |
|
PinkNoise(double alpha,
int poles)
Generate pink noise specifying alpha and the number of poles. |
|
PinkNoise(double alpha,
int poles,
java.util.Random random)
Generate pink noise from a specific randomness source specifying alpha and the number of poles. |
Method Summary | |
---|---|
static void |
main(java.lang.String[] arg)
A main method to demonstrate the functionality. |
double |
nextValue()
Return the next pink noise sample. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PinkNoise()
public PinkNoise(double alpha)
alpha
- the exponent of the pink noise, 1/f^alpha.
java.lang.IllegalArgumentException
- if alpha < 0
or
alpha > 2
.public PinkNoise(double alpha, int poles)
alpha
- the exponent of the pink noise, 1/f^alpha.poles
- the number of poles to use.
java.lang.IllegalArgumentException
- if alpha < 0
or
alpha > 2
.public PinkNoise(double alpha, int poles, java.util.Random random)
alpha
- the exponent of the pink noise, 1/f^alpha.poles
- the number of poles to use.random
- the randomness source.
java.lang.IllegalArgumentException
- if alpha < 0
or
alpha > 2
.Method Detail |
---|
public double nextValue()
public static void main(java.lang.String[] arg)
java PinkNoise samples [alpha [poles]] samples = number of samples to output alpha = PSD distribution exponent, 1/f^alpha (default 1.0) poles = number of IIR poles to use (default 5)