pathsim.blocks.rf.noise module

class pathsim.blocks.rf.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.

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

sigma

sqrt of spectral density -> signal amplitude

Type:

float

n_samples

internal sample counter

Type:

int

reset()[source]

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

sample(t)[source]

Sample from a normal distribution after successful timestep

Parameters:

t (float) – evaluation time for sampling

update(t)[source]

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

Note

no direct passthrough, so the ‘update’ method is optimized for this case

Parameters:

t (float) – evaluation time

Returns:

error – absolute error to previous iteration for convergence control (here ‘0.0’ because source-type block)

Return type:

float

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

Bases: Block

Pink noise (1/f) source using the Voss-McCartney algorithm.

Samples from distribution with ‘sampling_rate’ and generates noise with a power spectral density inversely proportional to frequency.

Parameters:
  • spectral_density (float) – Desired noise spectral density

  • num_octaves (int) – Number of octaves (levels of randomness)

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

sigma

sqrt of spectral density normalized to number of octaves

Type:

float

n_samples

internal sample counter

Type:

int

noise

internal noise value

Type:

float

octaves_values

internal random numbers for octaves in the Voss-McCartney algorithm

Type:

array[float]

reset()[source]

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

sample(t)[source]

Generate a new pink noise sample at ‘t’ using the Voss-McCartney algorithm.

Parameters:

t (float) – evaluation time for sampling

update(t)[source]

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

Note

no direct passthrough, so the ‘update’ method is optimized for this case

Parameters:

t (float) – evaluation time

Returns:

error – absolute error to previous iteration for convergence control (here ‘0.0’ because source-type block)

Return type:

float

class pathsim.blocks.rf.noise.SinusoidalPhaseNoiseSource(frequency=1, amplitude=1, phase=0, sig_cum=0, sig_white=0, sampling_rate=10)[source]

Bases: Block

Sinusoidal source with cumulative and white phase noise

Parameters:
  • frequency (float) – frequency of the sinusoid

  • amplitude (float) – amplitude of the sinusoid

  • phase (float) – phase of the sinusoid

  • sig_cum (float) – weight for cumulative phase noise contribution

  • sig_white (float) – weight for white phase noise contribution

  • sampling_rate (float) – number of samples per unit time for the internal RNG

omega

angular frequency of the sinusoid, derived from frequency

Type:

float

noise_1

internal noise value sampled from normal distribution

Type:

float

noise_2

internal noise value sampled from normal distribution

Type:

float

n_samples

bin counter for sampling

Type:

int

t_max

most recent sampling time, to ensure timing for sampling bins

Type:

float

set_solver(Solver, **solver_kwargs)[source]

Initialize the numerical integration engine with local truncation error tolerance if required.

If the block already has an integration engine, it is changed, if it does not require an integration engine, this method just passes.

Parameters:
  • Solver (Solver) – numerical integrator

  • solver_args (dict) – additional args for the solver

reset()[source]

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

update(t)[source]

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

Note

no direct passthrough, so the ‘update’ method is optimized for this case

Parameters:

t (float) – evaluation time

Returns:

error – absolute error to previous iteration for convergence control (here ‘0.0’ because source-type block)

Return type:

float

sample(t)[source]

Sample from a normal distribution after successful timestep.

solve(t, dt)[source]

The ‘solve’ method performes one iterative solution step that is required to solve the implicit update equation of the solver if an implicit solver (numerical integrator) is used.

It returns the relative difference between the new updated solution and the previous iteration of the solution to track convergence within an outer loop.

This only has to be implemented by blocks that have an internal integration engine with an implicit solver.

Parameters:
  • t (float) – evaluation time

  • dt (float) – integration timestep

Returns:

error – solver residual norm

Return type:

float

step(t, dt)[source]

The ‘step’ method is used in transient simulations and performs an action (numeric integration timestep, recording data, etc.) based on the current inputs and the current internal state.

It performes one timestep for the internal states. For instant time blocks, the ‘step’ method does not has to be implemented specifically.

The method handles timestepping for dynamic blocks with internal states such as ‘Integrator’, ‘StateSpace’, etc.

Parameters:
  • t (float) – evaluation time

  • dt (float) – integration timestep

Returns:

  • success (bool) – step was successful

  • error (float) – local truncation error from adaptive integrators

  • scale (float) – timestep rescale from adaptive integrators