schtrig
(x,lvl,rst=1) ¶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.
The following code
t = linspace(0,1,100)'; x = sin (2*pi*2*t) + sin (2*pi*5*t).*[0.8 0.3]; lvl = [0.8 0.25]'; v = schtrig (x,lvl); subplot(2,1,1) h = plot (t, x(:,1), t, v(:,1)); set (h, 'linewidth',2); line([0; 1],lvl([1; 1]),'color','g'); line([0;1],lvl([2;2]),'color','k') axis tight subplot(2,1,2) h = plot (t, x(:,2), t, v(:,2)); set (h,'linewidth',2); line([0; 1],lvl([1; 1]),'color','g'); line([0;1],lvl([2;2]),'color','k') axis tight
Produces the following figure
Figure 1 |
---|
Package: signal