Noise

class pathsim.blocks.noise.WhiteNoise(spectral_density=1, sampling_rate=None)[source]

Bases: Block

White 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:
  • spectral_density (float) – noise spectral density

  • noise (float) – internal noise value

  • sampling_rate (float, None) – frequency with which the noise is sampled

events

scheduled event for periodic sampling

Type:

list[Schedule]

input_port_labels = {}
output_port_labels = {'out': 0}
sample(t, dt)[source]

Sample from a normal distribution after successful timestep

Parameters:
  • t (float) – evaluation time for sampling

  • dt (float) – integration timestep

update(t)[source]

update system equation for fixed point loop, here just setting the outputs

Parameters:

t (float) – evaluation time

class pathsim.blocks.noise.PinkNoise(spectral_density=1, num_octaves=16, sampling_rate=None)[source]

Bases: Block

Pink 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_octaves independent 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:
  • spectral_density (float) – noise spectral density \(S_0\)

  • num_octaves (int) – number of octaves (levels of randomness), default is 16

  • sampling_rate (float, None) – frequency with which the noise is sampled

n_samples

internal sample counter

Type:

int

octave_values

internal random numbers for octaves in the Voss-McCartney algorithm

Type:

array[float]

events

scheduled event for periodic sampling

Type:

list[Schedule]

References

input_port_labels = {}
output_port_labels = {'out': 0}
reset()[source]

Reset the blocks inputs and outputs and also its internal solver, if the block has a solver instance.

sample(t, dt)[source]

Sample pink noise after successful timestep.

Parameters:
  • t (float) – evaluation time for sampling

  • dt (float) – integration timestep

update(t)[source]

update system equation for fixed point loop, here just setting the outputs

Parameters:

t (float) – evaluation time