Signal Toolkit - schtrig


v =: schtrig (x,lvl,rst=1)
[v,rng] =: schtrig (…)

Implements a multisignal Schmitt trigger with levels lvl.

The triger works along the first dimension of the 2-dimensional array x. It compares each column in x to the levels in lvl, when the value is higher max (lvl) the output v is high (i.e. 1); when the value is below min (lvl) the output is low (i.e. 0); and when the value is between the two levels the output retains its value.

The threshold levels are passed in the array lvl. If this is a scalar, the thresholds are symmetric around 0, i.e. [-lvl lvl].

The second output argument stores the ranges in which the output is high, so the indexes rng(1,i):rng(2,i) point to the i-th segment of 1s in v. See clustersegment for a detailed explanation.

The function conserves the state of the trigger across calls (persistent variable). If the reset flag is active, i.e. rst== true, then the state of the trigger for all signals is set to the low state (i.e. 0).

Example:

 x = [0 0.5 1 1.5 2 1.5 1.5 1.2 1 0 0].';
 y = schtrig (x, [1.3 1.6]);
 disp ([x y]);
   0.0   0
   0.5   0
   1.0   0
   1.5   0
   2.0   1
   1.5   1
   1.5   1
   1.2   0
   1.0   0
   0.0   0
   0.0   0
 

Run demo schtrig to see further examples.

See also: clustersegment.