pathsim.blocks.noise module¶
- class pathsim.blocks.noise.WhiteNoise(spectral_density=1, sampling_rate=None)[source]¶
Bases:
BlockWhite noise source with uniform spectral density. Samples from distribution with ‘sampling_rate’ and holds noise values constant for time bins (zero-order-hold).
If no ‘sampling_rate’ (None) is specified, every simulation timestep gets a new noise value. This is the default setting.
- Parameters:
- class pathsim.blocks.noise.PinkNoise(spectral_density=1, num_octaves=16, sampling_rate=None)[source]¶
Bases:
BlockPink noise (1/f) source using the Voss-McCartney algorithm.
Generates noise with power spectral density inversely proportional to frequency. Samples from distribution with ‘sampling_rate’ and holds noise values constant for time bins (zero-order-hold).
The Voss-McCartney algorithm maintains
num_octavesindependent random values. At each sample n, octaves are selectively updated based on the binary representation of n:Octave 0: updated every sample (when n & 1 == 1)
Octave 1: updated every 2nd sample (when n & 2 == 2)
Octave 2: updated every 4th sample (when n & 4 == 4)
Octave k: updated every \(2^k\) samples
The pink noise output is the sum of all octaves, scaled to achieve the desired spectral density:
\[y[n] = \sqrt{\frac{S_0}{N \cdot dt}} \sum_{k=0}^{N-1} x_k[n]\]where \(S_0\) is the spectral density, \(N\) is
num_octaves, \(dt\) is the sampling timestep, and \(x_k[n]\) are the octave values (each drawn from \(\mathcal{N}(0, 1)\) when updated).Note
If no ‘sampling_rate’ (None) is specified, every simulation timestep gets a new noise value. This is the default setting.
- Parameters:
- octave_values¶
internal random numbers for octaves in the Voss-McCartney algorithm
- Type:
array[float]
References
- reset()[source]¶
Reset the blocks inputs and outputs and also its internal solver, if the block has a solver instance.