I am trying to mimic the behavoir of the Matlab's Simulink relay block with just Matlab code. My code is as follows (not familiar with persistent variable? click):
function out = fcn(u,delta)
persistent y;
if isempty(y)
y = 0;
end
if u >= delta
y = 1;
elseif u <= -delta
y = 0;
end
out = y;
When I look to the output I and compare with the real relay block I see:
Where does the difference come from? Both blocks inhert the same sample time? Or does the relay block have something extra to show the discontinuity?
MATLAB function
block inherts the sample time of the solver. – WG-