Qu

find_edges

Builtin index · Signal processing

result = find_edges(x, [level=], [threshold=], [hysteresis=0])

Input: x, level, threshold, hysteresis · Output: result

What it is

x: a length-N real vector or Signal; level=/threshold= (optional number, same thing under two names) defaults to the signal's own midpoint (min+max)/2; hysteresis (optional number, default 0): with 0 this is a plain single-threshold detector, i.e. find_trigger run in both directions; with a positive value it is a Schmitt trigger requiring level + hysteresis/2 to call high and level - hysteresis/2 to call low, so noise on a slow edge yields one edge rather than a burst. The reported positions are taken at level either way, so switching hysteresis on to reject glitches does not move the measurements it protects.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = find_edges(x, [level=], [threshold=], [hysteresis=0])
x vector or Signalx: a length-N real vector or Signal.
level number, optionallevel=/threshold= (optional number, same thing under two names) defaults to the signal's own midpoint (min+max)/2.
threshold number, optionalhysteresis (optional number, default 0): with 0 this is a plain single-threshold detector, i.e.
hysteresis number, optional (default 0)hysteresis (optional number, default 0): with 0 this is a plain single-threshold detector, i.e.
Model —kind "edges"
indices vectora vector of integer sample indices
directions vectora vector, +1 rising / -1 falling, parallel to indices
positions vectora vector of interpolated sub-sample crossing points
falling —the two index splits
count numbera number
Returns a Model (kind "edges") with fields indices (a vector of integer sample indices), directions (a vector, +1 rising / -1 falling, parallel to indices), positions (a vector of interpolated sub-sample crossing points), rising and falling (the two index splits), and count (a number).

Examples

No documentation example calls this form yet. The Signal processing chapter is where one belongs.

How it works

find_edges(x, [level=], [hysteresis=]) -- rising AND falling edges together, as a Model with parallel fields indices (integer sample indices), directions (+1 for a rising edge, -1 for a falling one), positions (the interpolated sub-sample crossing points), and the two convenience splits rising/falling. level defaults to the signal's own midpoint, (min+max)/2 -- the right default for the digital-ish signals this is for, and the one thing about a logic waveform that can be inferred without guessing. hysteresis defaults to 0, i.e. a plain single-threshold detector, which is find_trigger run in both directions. Hysteresis is offered rather than imposed: a Schmitt scheme is the right tool for a noisy analog edge, but making it the DEFAULT would mean every caller silently got a detector with a band whose width the engine chose, and on a clean signal it changes nothing while making the behaviour harder to predict. Passing hysteresis= opts in; the measured positions stay at level either way, so switching it on to reject glitches does not move the numbers it is protecting.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.