pathsim.blocks.mixed.comparator module

class pathsim.blocks.mixed.comparator.Comparator(threshold=0, tolerance=0.0001, span=[-1, 1])[source]

Bases: Block

Comparator block that sets the output to ‘1’ it the input signal crosses a predefined threshold and to ‘-1’ if it crosses in the reverse direction.

This is realized by the block spawning a zero-crossing event detector that watches the input of the block and locates the transition up to a tolerance.

The block output is determined by a simple sign check in the ‘update’ method.

Parameters:
  • threshold (float) – threshold value for the comparator

  • tolerance (float) – tolerance for zero crossing detection

  • span (list[float] or tuple[float], optional) – output value range [min, max]

events

internal zero crossing event

Type:

list[ZeroCrossing]

update(t)[source]

The ‘update’ method is called iteratively for all blocks to evaluate the algbebraic components of the global system ode and resolve algebraic loops (fixed-point iteraion).

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.

It computes and returns the absolute difference between the new output and the previous output (before the call) to track convergence of the fixed-point iteration.

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

Returns:

error – absolute error to previous iteration for convergence control

Return type:

float