Comparator

Shipping
comparator

Element-wise comparison → boolean signal (1.0/0.0)

Signature

Inputs

  • aSignalrequired
  • bSignal

Outputs

  • resultSignal
  • boolScalar

Parameters

KeyTypeDefaultNotes
operationenumgreaterone of: greater, less, greaterEqual, lessEqual, equal, notEqual
thresholdfloat0.0
tolerancefloat0.0

Description

The Comparator performs an element-wise comparison of input a against a reference and emits a boolean-valued signal encoded as (true) and (false). The reference is the second signal input b when wired; otherwise it falls back to the scalar threshold parameter. The operation parameter selects one of greater, less, greaterEqual, lessEqual, equal, or notEqual, applied sample-by-sample.

Two outputs are produced. result is a Signal of the same length (and sample rate) as a, holding the per-sample boolean. bool is a Scalar reduction that is if any sample of result is high and otherwise — a convenient trigger/alarm flag for threshold-crossing detection.

For the equal and notEqual operations, the tolerance parameter () applies symmetric slack so that samples within tolerance of the reference are treated as equal. This is essential for floating-point comparisons, where exact equality is almost never met. Tolerance is ignored by the ordering operations.

The node is stateless — each block is evaluated independently with no carry-over. The output is a pure boolean magnitude and is therefore dimensionless: physical units on a and b are used only to align the comparison and do not propagate. Because the result is a hard decision, input uncertainty () does not flow to the output; a sample near the threshold collapses to a definite boolean regardless of its variance.

Mathematics

Examples

Threshold alarm with scalar reference

Leave b unwired and set operation = greater, threshold = 4.5. Every sample of a above becomes ; the bool output fires the moment any sample in the block exceeds the limit, driving a downstream indicator or sink.

a = [4.1, 4.6, 4.4, 5.0]
result = [0, 1, 0, 1]
bool   = 1.0

Tolerant equality between two signals

Wire a measured signal into a and a setpoint into b, set operation = equal, tolerance = 0.05. A sample counts as equal when , so against yields despite the floating-point mismatch.

Applications

  • Level/threshold detection in DAQ pipelines — flagging over-voltage, over-temperature, or out-of-range samples.
  • Building digital control logic by feeding boolean results into logic_gate networks for interlocks and state machines.
  • Automated pass/fail test benches, using tolerant equal/notEqual comparison of a measured response against a reference trace.
  • Event gating and masking, where the 1.0/0.0 signal multiplies another stream to zero out samples that fail a condition.

Neat

The scalar `bool` output is exactly the logical OR (max) over the boolean signal, so a single Comparator doubles as both a per-sample mask and a block-level 'any-crossing' trigger.

Because the output is a definite {0,1} decision, measurement uncertainty does not propagate through it — a deliberate design choice, since a boolean has no meaningful sigma. Use schmitt_trigger or peak_detection when noise-robust crossing is required.

Known issues

`equal` / `notEqual` with the default `tolerance = 0.0` demand bit-exact floating-point equality and will almost always return 0.0 for computed inputs; set a non-zero tolerance for real-valued comparisons.

With chattering inputs near the threshold, `result` toggles on every noisy sample (no hysteresis). Use schmitt_trigger when clean, debounced crossings are needed.

See also

comparisonthresholdbooleanlogicdetectionstateless