BlockWerk Documentation
≥

Comparator

Logic

The Comparator block compares an input signal to a threshold and outputs a binary result: 1 (true) if the comparison is satisfied, 0 (false) otherwise. Essential for threshold detection, crossing detection, and generating boolean control signals.

Simulate in BlockWerk

Interactive sandbox directly in your browser — zero installation, WASM-powered.

Simulate in BlockWerk →

Mathematical Model

y={1,if u op threshold0,otherwiseop∈{≥,>,≤,<,=,≠}y = \begin{cases} 1, & \text{if } u \text{ op } \text{threshold} \\ 0, & \text{otherwise} \end{cases} \\ \text{op} \in \{ \ge, >, \le, <, =, \neq \}

Inputs & Outputs

Direction ID Label Type Status
→ In in Input number Required
← Out out Output number Output

Parameters

Parameters Label Type Default Description
operator Operator select >=
threshold Threshold number 0
trueResultMode True Output select constant
trueValue True Constant number 1
falseResultMode False Output select constant
falseValue False Constant number 0

Usage Examples

Threshold Crossing Detection (1 second)

Ramp signal (0→5) compared against threshold=2.5. Output is 0 until signal crosses threshold at t=0.5s, then becomes 1.

Hysteresis Implementation

Compare high and low thresholds to create switching with hysteresis.

Remarks & Best Practices

  • Binary Output: Always 0 or 1, ideal for logic circuits
  • Instantaneous: No delay, combinatorial block
  • Floating Point: Equality uses tolerance (1e-9) for robust comparisons
  • Threshold Detection: Common in alarm and control systems
  • Selector Input: Can drive Switch block for conditional routing

Related Components

  • Switch: Routes signals based on Comparator output
  • Gain: Scale signal before comparison
  • Subtraction: Compute error for threshold
  • Step: Generate selector signal manually