Jairo,
this is an interesting problem! Here is a simple outline how it could be done:
vccPlus = 1;
vccMinus = -1;
vh = 0.75;
vl = -0.75;
schmitt[x_] := Which[(state == -1) && (x > vh), (state = 1; vccPlus),
(state == 1) && (x > vl), vccPlus,
(state == 1) && (x < vl), (state = -1; vccMinus),
(state == -1) && (x < vh), vccMinus]
Using this with some proper initialization:
state = -1; (* "quick and dirty" initialization - just for the example! *)
dataSchmitt = Table[{x, schmitt[Sin[x]]}, {x, 0, 4 Pi, .1}];
dataSin = Table[{x, Sin[x]}, {x, 0, 4 Pi, .1}];
ListLinePlot[{dataSchmitt, dataSin}, GridLines -> {None, {vl, vh}}]
For this method to work it is necessary that the function points are evaluated in order (from left to right, so to speak). For this reason I generate explicit values and use ListLinePlot
. Using simply
state = -1;
Plot[{schmitt[Sin[x]], Sin[x]}, {x, 0, 2 Pi}]
does not work in a clean way, because here there is no clear order of evaluation.
I am curious myself how this could be done in a better and more robust way!