Sources

class pathsim.blocks.sources.Constant(value=1)[source]

Bases: Block

Produces a constant output signal (SISO)

Parameters:

value (float) – constant defining block output

update(t)[source]

update system equation fixed point loop

Parameters:

t (float) – evaluation time

Returns:

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

Return type:

float

class pathsim.blocks.sources.Source(func=<function Source.<lambda>>)[source]

Bases: Block

Source that produces an arbitrary time dependent output, defined by the func (callable).

\[y(t) = \mathrm{func}(t)\]

Note

This block is purely algebraic and its internal function (func) will be called multiple times per timestep, each time when Simulation._update(t) is called in the global simulation loop.

Example

For example a ramp:

from pathsim.blocks import Source

src = Source(lambda t : t)

or a simple sinusoid with some frequency:

import numpy as np
from pathsim.blocks import Source

#some parameter
omega = 100

#the function that gets evaluated
def f(t):
    return np.sin(omega * t)

src = Source(f)

Because the Source block only has a single argument, it can be used to decorate a function and make it a PathSim block. This might be handy in some cases to keep definitions concise and localized in the code:

import numpy as np
from pathsim.blocks import Source

#does the same as the definition above

@Source
def src(t):
    omega = 100
    return np.sin(omega * t)

#'src' is now a PathSim block
Parameters:

func (callable) – function defining time dependent block output

update(t)[source]

update system equation fixed point loop by evaluating the internal function ‘func’

Note

No direct passthrough, so the update method is optimized and has no convergence check

Parameters:

t (float) – evaluation time

class pathsim.blocks.sources.TriangleWaveSource(frequency=1, amplitude=1, phase=0)[source]

Bases: Block

Source block that generates an analog triangle wave

Parameters:
  • frequency (float) – frequency of the triangle wave

  • amplitude (float) – amplitude of the triangle wave

  • phase (float) – phase of the triangle wave

update(t)[source]

The ‘update’ method is called iteratively for all blocks to evaluate the algebraic components of the global system ode from the DAG.

It is meant for instant time blocks (blocks that dont have a delay due to the timestep, such as Amplifier, etc.) and updates the ‘outputs’ of the block directly based on the ‘inputs’ and possibly internal states.

Note

The implementation of the ‘update’ method in the base ‘Block’ class is intended as a fallback and is not performance optimized. Special blocks might reimplement this method differently for higher performance, for example SISO or MISO blocks.

Parameters:

t (float) – evaluation time

class pathsim.blocks.sources.SinusoidalSource(frequency=1, amplitude=1, phase=0)[source]

Bases: Block

Source block that generates a sinusoid wave

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

  • amplitude (float) – amplitude of the sinusoid

  • phase (float) – phase of the sinusoid

update(t)[source]

The ‘update’ method is called iteratively for all blocks to evaluate the algebraic components of the global system ode from the DAG.

It is meant for instant time blocks (blocks that dont have a delay due to the timestep, such as Amplifier, etc.) and updates the ‘outputs’ of the block directly based on the ‘inputs’ and possibly internal states.

Note

The implementation of the ‘update’ method in the base ‘Block’ class is intended as a fallback and is not performance optimized. Special blocks might reimplement this method differently for higher performance, for example SISO or MISO blocks.

Parameters:

t (float) – evaluation time

class pathsim.blocks.sources.GaussianPulseSource(amplitude=1, f_max=1000.0, tau=0.0)[source]

Bases: Block

Source block that generates a gaussian pulse

Parameters:
  • amplitude (float) – amplitude of the gaussian pulse

  • f_max (float) – maximum frequency component of the gaussian pulse (steepness)

  • tau (float) – time delay of the gaussian pulse

update(t)[source]

The ‘update’ method is called iteratively for all blocks to evaluate the algebraic components of the global system ode from the DAG.

It is meant for instant time blocks (blocks that dont have a delay due to the timestep, such as Amplifier, etc.) and updates the ‘outputs’ of the block directly based on the ‘inputs’ and possibly internal states.

Note

The implementation of the ‘update’ method in the base ‘Block’ class is intended as a fallback and is not performance optimized. Special blocks might reimplement this method differently for higher performance, for example SISO or MISO blocks.

Parameters:

t (float) – evaluation time

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

Generates a sinusoid with additive phase noise from two components:

  • White phase noise: sampled from a normal distribution at each sample

  • Cumulative phase noise: integrated random walk process

The output is given by:

\[y(t) = A \sin\left(\omega t + \varphi_0 + \sigma_w n_w(t) + \sigma_c \int_0^t n_c(\tau) d\tau\right)\]

where \(A\) is amplitude, \(\omega = 2\pi f\) is angular frequency, \(\varphi_0\) is initial phase, \(\sigma_w\) and \(\sigma_c\) are the white and cumulative noise weights, and \(n_w(t)\) and \(n_c(t)\) are independent standard normal random processes sampled at the specified sampling rate.

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

  • amplitude (float) – amplitude of the sinusoid

  • phase (float) – initial phase of the sinusoid (radians)

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

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

  • sampling_rate (float, None) – frequency with which the phase noise is sampled (Hz). If None, noise is sampled every timestep (default is 10 Hz)

omega

angular frequency of the sinusoid, derived from frequency

Type:

float

noise_1

internal noise value for white phase noise

Type:

float

noise_2

internal noise value for cumulative phase noise

Type:

float

events

scheduled event for periodic sampling (only if sampling_rate is set)

Type:

list[Schedule]

set_solver(Solver, parent, **solver_kwargs)[source]

Initialize or change the numerical integration engine for cumulative noise.

Parameters:
  • Solver (class) – solver class to instantiate

  • parent (object) – parent system object

  • **solver_kwargs (dict) – additional keyword arguments for solver initialization

reset()[source]

Reset block state including noise samples.

update(t)[source]

Update system equation for fixed point loop, evaluating the sinusoid with phase noise.

Parameters:

t (float) – evaluation time

sample(t, dt)[source]

Sample from a normal distribution after successful timestep.

Only used when sampling_rate is None (continuous sampling).

Parameters:
  • t (float) – evaluation time

  • dt (float) – integration timestep

solve(t, dt)[source]

Advance solution of implicit update equation for cumulative noise integration.

Parameters:
  • t (float) – evaluation time

  • dt (float) – integration timestep

Returns:

error estimate (always 0.0 for noise source)

Return type:

float

step(t, dt)[source]

Compute update step with integration engine for cumulative noise.

Parameters:
  • t (float) – evaluation time

  • dt (float) – integration timestep

Returns:

(accepted, error, scale_factor) - always (True, 0.0, 1.0) for noise

Return type:

tuple

class pathsim.blocks.sources.ChirpPhaseNoiseSource(amplitude=1, f0=1, BW=1, T=1, phase=0, sig_cum=0, sig_white=0, sampling_rate=10)[source]

Bases: Block

Chirp source, sinusoid with frequency ramp up and ramp down, plus phase noise.

This works by using a time dependent triangle wave for the frequency and integrating it with a numerical integration engine to get a continuous phase. This phase is then used to evaluate a sinusoid.

Additionally the chirp source can have white and cumulative phase noise. Mathematically it looks like this for the contributions to the phase from the triangular wave:

\[\varphi_t(t) = \int_0^t \mathrm{tri}_{f_0, B, T}(\tau) \, d\tau\]

And from the white (w) and cumulative (c) noise:

\[\varphi_n(t) = \sigma_w \, n_w(t) + \sigma_c \int_0^t n_c(\tau) \, d\tau\]

The phase contributions are then used to evaluate a sinusoid to get the final chirp signal:

\[y(t) = A \sin(\varphi_t(t) + \varphi_n(t) + \varphi_0)\]
Parameters:
  • amplitude (float) – amplitude of the chirp signal

  • f0 (float) – start frequency of the chirp signal

  • BW (float) – bandwidth of the frequency ramp of the chirp signal

  • T (float) – period of the frequency ramp of the chirp signal

  • phase (float) – phase of sinusoid (initial, radians)

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

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

  • sampling_rate (float, None) – frequency with which phase noise is sampled (Hz). If None, noise is sampled every timestep (default is 10 Hz)

noise_1

internal noise value for white phase noise

Type:

float

noise_2

internal noise value for cumulative phase noise

Type:

float

events

scheduled event for periodic sampling (only if sampling_rate is set)

Type:

list[Schedule]

reset()[source]

Reset block state including noise samples.

set_solver(Solver, parent, **solver_kwargs)[source]

Initialize or change the numerical integration engine for phase integration.

Parameters:
  • Solver (class) – solver class to instantiate

  • parent (object) – parent system object

  • **solver_kwargs (dict) – additional keyword arguments for solver initialization

sample(t, dt)[source]

Sample from a normal distribution after successful timestep to update internal noise samples.

Only used when sampling_rate is None (continuous sampling).

Parameters:
  • t (float) – evaluation time

  • dt (float) – integration timestep

update(t)[source]

Update the block output, assemble phase and evaluate the sinusoid.

Parameters:

t (float) – evaluation time

solve(t, dt)[source]

Advance implicit solver of implicit integration engine, evaluate the triangle wave and cumulative noise RNG.

Parameters:
  • t (float) – evaluation time

  • dt (float) – integration timestep

Returns:

error estimate (always 0.0 for chirp source)

Return type:

float

step(t, dt)[source]

Compute update step with integration engine, evaluate the triangle wave and cumulative noise RNG.

Parameters:
  • t (float) – evaluation time

  • dt (float) – integration timestep

Returns:

(accepted, error, scale_factor) - always (True, 0.0, 1.0) for chirp

Return type:

tuple

class pathsim.blocks.sources.ChirpSource(amplitude=1, f0=1, BW=1, T=1, phase=0, sig_cum=0, sig_white=0, sampling_rate=10)[source]

Bases: ChirpPhaseNoiseSource

class pathsim.blocks.sources.PulseSource(amplitude=1.0, T=1.0, t_rise=0.0, t_fall=0.0, tau=0.0, duty=0.5)[source]

Bases: Block

Generates a periodic pulse waveform with defined rise and fall times using a hybrid approach with scheduled events and continuous updates.

Scheduled events trigger phase changes (low, rising, high, falling), and the update method calculates the output value based on the current phase, performing linear interpolation during rise and fall.

Parameters:
  • amplitude (float, optional) – Peak amplitude of the pulse. Default is 1.0.

  • T (float, optional) – Period of the pulse train. Must be positive. Default is 1.0.

  • t_rise (float, optional) – Duration of the rising edge. Default is 0.0.

  • t_fall (float, optional) – Duration of the falling edge. Default is 0.0.

  • tau (float, optional) – Initial delay before the first pulse cycle begins. Default is 0.0.

  • duty (float, optional) – Duty cycle, ratio of the pulse ON duration (plateau time only) to the total period T (must be between 0 and 1). Default is 0.5. The high plateau duration is T * duty.

events

Internal scheduled events triggering phase transitions.

Type:

list[Schedule]

_phase

Current phase of the pulse (‘low’, ‘rising’, ‘high’, ‘falling’).

Type:

str

_phase_start_time

Simulation time when the current phase began.

Type:

float

reset(t: float = None)[source]

Resets the block state.

Note

This block has a special implementation of reset where t can be provided to reset the block’s state to the specified time. This is done by changing the phase of the pulse + resetting all the internal events.

Parameters:

t (float, optional) – Time to reset the block state at. If None, resets to initial state.

update(t)[source]

Calculate the pulse output value based on the current phase. Performs linear interpolation during ‘rising’ and ‘falling’ phases.

Parameters:

t (float) – evaluation time

class pathsim.blocks.sources.Pulse(amplitude=1.0, T=1.0, t_rise=0.0, t_fall=0.0, tau=0.0, duty=0.5)[source]

Bases: PulseSource

class pathsim.blocks.sources.ClockSource(T=1, tau=0)[source]

Bases: Block

Discrete time clock source block.

Utilizes scheduled events to periodically set the block output to 0 or 1 at discrete times.

Parameters:
  • T (float) – period of the clock

  • tau (float) – clock delay

events

internal scheduled event list

Type:

list[Schedule]

class pathsim.blocks.sources.Clock(T=1, tau=0)[source]

Bases: ClockSource

class pathsim.blocks.sources.SquareWaveSource(amplitude=1, frequency=1, phase=0)[source]

Bases: Block

Discrete time square wave source.

Utilizes scheduled events to periodically set the block output at discrete times.

Parameters:
  • amplitude (float) – amplitude of the square wave signal

  • frequency (float) – frequency of the square wave signal

  • phase (float) – phase of the square wave signal

events

internal scheduled events

Type:

list[Schedule]

class pathsim.blocks.sources.StepSource(amplitude=1, tau=0.0)[source]

Bases: Block

Discrete time unit step source block.

Utilizes a scheduled event to set the block output to the specified output levels at the defined event times.

The arguments can be vectorial and in that case, the output is set to the amplitude that corresponds to the defined delay like a zero-order-hold stage. This functionality enables adding external or time series measurement data into the system.

Examples

This is how to use the source as a unit step source:

from pathsim.blocks import StepSource

#default, starts at 0, jumps to 1
stp = StepSource()

And this is how to configure it with multiple consecutive steps:

from pathsim.blocks import StepSource

#starts at 0, jumps to 1 at 1, jumps to -1 at 2 and jumps back to 0 at 3
stp = StepSource(amplitude=[1, -1, 0], tau=[1, 2, 3])

Similarly implementing measured time series data via zoh:

import numpy as np
from pathsim.blocks import StepSource

#some random time series arrays
times, data = np.linspace(0, 100, 1000), np.random.rand(1000)

#pass them to the block
stp = StepSource(amplitude=data, tau=times)
Parameters:
  • amplitude (float | list[float]) – amplitude of the step signal, or amplitudes / output levels of the multiple steps

  • tau (float | list[float]) – delay of the step, or delays of the different steps

Evt

internal scheduled event directly accessible

Type:

ScheduleList

events

list of interna events

Type:

list[ScheduleList]

class pathsim.blocks.sources.Step(amplitude=1, tau=0.0)[source]

Bases: StepSource