% Two hysteresis modulators
%
% -----------------------------------------------------------------------------------
%
% (C) 2017, Krzysztof Sozanski, Digital Signal Processing in Power Electronics Control 
% Circuits, second edition, Springer-Verlag, London, 2017. 
% 
% -----------------------------------------------------------------------------------
%
%
e=i_Cref(n)-i_C(n)*kr; 
e_s=i_Cref(n)-i_Cs(n)*kr;
if u_Cs>=0
  if e_s>kh*h
    u_Cs=u_C1-u_M(n);
    if e<-h&&u_Cf>=0 
      u_Uf=u_C2-u_M(n); 
    elseif e>h&&u_Cf<=0
      u_Cf=u_C2-u_M(n);
    end
  else
    u_Cf=0;
    if blad<-h 
      u_Cs=u_C2-u_M(n); 
    else
      u_Cs=u_C1-u_M(n);
    end
  end
else %u_Cs <0
  if e_s<-kh*h
    u_Cs=u_C2-u_M(n);
    if e<-h&&u_Cf>=0 
      u_Cf=u_C2-u_M(n); 
    elseif e>h&&u_Cf<=0
      u_Cf=u_C1-u_M(n);
    end
  else
    u_Cf=0;
    if e>h 
      u_Cs=u_C1-u_M(n); 
    else
      u_Cs=u_C2-u_M(n);
    end
  end       
end
