Comparator

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

Bases: Block

Comparator block that sets output depending on predefined thresholds for the input.

Sets the output to ‘1’ if 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]

input_port_labels = {'in': 0}
output_port_labels = {'out': 0}
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 discrete block)

Return type:

float