↗

Edge Detect

Logic
Run the live example Free · no sign-up · runs in your browser

The EdgeDetect block monitors an incoming continuous or discrete signal and emits a boolean pulse (1.01.0 or 0.00.0) whenever the signal crosses a specified threshold or changes state. It supports detection of rising transitions (crossing from below to at or above threshold), falling transitions (crossing from above to below threshold), or bidirectional threshold crossings.

The output pulse remains asserted for exactly one simulation time step (TsT_s) upon detection of an edge, making it an indispensable trigger block for event counters, state machines, latch resets, and sample-and-hold circuits.

Mathematical Model

Let u[n]u[n] be the input sample at discrete step nn, and let s[n]∈{0,1}s[n] \in \{0, 1\} represent the boolean threshold state relative to threshold θ\theta:

s[n]={1,u[n]≥θ0,u[n]<θs[n] = \begin{cases} 1, & u[n] \ge \theta \\ 0, & u[n] < \theta \end{cases}

The output pulse y[n]y[n] is generated based on the selected detection mode:

Rising:y[n]={1,s[n]=1 and s[n−1]=00,otherwiseFalling:y[n]={1,s[n]=0 and s[n−1]=10,otherwiseEither:y[n]={1,s[n]≠s[n−1]0,otherwise\begin{aligned} \text{Rising:} \quad & y[n] = \begin{cases} 1, & s[n] = 1 \text{ and } s[n-1] = 0 \\ 0, & \text{otherwise} \end{cases} \\ \text{Falling:} \quad & y[n] = \begin{cases} 1, & s[n] = 0 \text{ and } s[n-1] = 1 \\ 0, & \text{otherwise} \end{cases} \\ \text{Either:} \quad & y[n] = \begin{cases} 1, & s[n] \neq s[n-1] \\ 0, & \text{otherwise} \end{cases} \end{aligned}

At the initial simulation time step n=0n = 0, the preceding state s[−1]s[-1] is initialized to the configured initialState parameter.

Inputs & Outputs

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

Parameters

Parameters Label Type Default Description
mode Detection Mode select rising
threshold Threshold number 0.5 Signal level separating low from high. An edge is a crossing of this level; move it outside the noise band to avoid spurious edges.
initialState Initial State number 0

Usage Examples

Example 1: Optical Encoder Pulse Edge Detection

Detecting transitions from an optical rotary encoder output to drive an incrementing pulse counter. Setting mode = "rising" and threshold = 2.5 V on a 0–5 V digital signal generates a clean one-step pulse every time the encoder flag passes the sensor.

Example 2: Zero-Crossing Detector for AC Phase Synchronization

Detecting zero-crossings of an AC sinusoidal voltage signal. Setting threshold = 0.0 and mode = "either" triggers a pulse at every half-period crossing, allowing downstream logic to measure grid frequency or synchronize thyristor firing angles.

Remarks & Best Practices

  • Single-Step Pulse Duration: Output is asserted to 1.01.0 for exactly one simulation time step TsT_s per detected crossing before returning to 0.00.0.
  • Noise Sensitivity: In the presence of noisy analog signals near threshold, rapid chattering or spurious edge triggers can occur. Pre-filter the signal with a DigitalFilter or DeadZone block if noise immunity is required.
  • Initial Step Response: Setting initialState properly prevents or enforces an edge trigger on the very first simulation step when the initial signal value is non-zero.
  • Signal Compatibility: Works transparently with both continuous analog signals and discrete boolean signals.

Related Components

  • Comparator: Continuous-time two-level comparator without one-shot pulse behavior.
  • IntervalTest: Tests whether a signal lies inside or outside a specified numeric range.
  • Relay: Switching element featuring a configurable hysteresis band.
  • UnitDelay: Single-step delay for discrete state tracking.