pathsim.blocks.mixed.comparator module

class pathsim.blocks.mixed.comparator.Comparator(threshold=0, tolerance=0.0001)[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

events

internal zero crossing event

Type:

list[ZeroCrossing]

update(t)[source]

The ‘update’ method is called iteratively for all blocks BEFORE the timestep to 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 relative difference between the new output and the previous output (before the step) to track convergence of the fixed-point iteration.

Parameters:

t (float) – evaluation time

Returns:

error – relative error to previous iteration for convergence control

Return type:

float