# Generator¶

The generator module provides signal generators.

The following functions calculate N samples and return an array containing the samples.

For indefinitely long iteration over the samples, consider using the output of these functions in itertools.cycle().

## Noise¶

Different types of noise are available. The following table lists the color of noise and how the power and power density change per octave.

Color Power Power density
White +3 dB 0 dB
Pink 0 dB -3 dB
Blue +6 dB +3 dB
Brown -3 dB -6 dB
Violet +9 dB +6 dB

The colored noise is created by generating pseudo-random numbers using np.random.randn() and then multiplying these with a curve tyical for the color. Afterwards, an inverse DFT is performed using np.fft.irfft(). Finally, the noise is normalized using acoustics.signal.normalize().

### All colors¶

acoustics.generator.noise(N, color='white', state=None)[source]

Noise generator.

Parameters: N – Amount of samples. color – Color of noise. state (np.random.RandomState) – State of PRNG.
acoustics.generator.noise_generator(N=44100, color='white', state=None)[source]

Noise generator.

Parameters: N – Amount of unique samples to generate. color – Color of noise.

Generate N amount of unique samples and cycle over these samples.

### Per color¶

acoustics.generator.white(N, state=None)[source]

White noise.

Parameters: N – Amount of samples. state (np.random.RandomState) – State of PRNG.

White noise has a constant power density. It’s narrowband spectrum is therefore flat. The power in white noise will increase by a factor of two for each octave band, and therefore increases with 3 dB per octave.

acoustics.generator.pink(N, state=None)[source]

Pink noise.

Parameters: N – Amount of samples. state (np.random.RandomState) – State of PRNG.

Pink noise has equal power in bands that are proportionally wide. Power density decreases with 3 dB per octave.

acoustics.generator.blue(N, state=None)[source]

Blue noise.

Parameters: N – Amount of samples. state (np.random.RandomState) – State of PRNG.

Power increases with 6 dB per octave. Power density increases with 3 dB per octave.

acoustics.generator.brown(N, state=None)[source]

Violet noise.

Parameters: N – Amount of samples. state (np.random.RandomState) – State of PRNG.

Power decreases with -3 dB per octave. Power density decreases with 6 dB per octave.

acoustics.generator.violet(N, state=None)[source]

Violet noise. Power increases with 6 dB per octave.

Parameters: N – Amount of samples. state (np.random.RandomState) – State of PRNG.

Power increases with +9 dB per octave. Power density increases with +6 dB per octave.

## Other¶

acoustics.generator.heaviside(N)[source]

Heaviside.

Returns the value 0 for x < 0, 1 for x > 0, and 1/2 for x = 0.

For related functions, check scipy.signal.