function B = fstab(A);
%FSTAB  FSTAB(A) stabilizes a MONIC polynomial with respect to the
%   unit circle, i.e. roots whose magnitudes are greater than
%   one are reflected into the unit circle.  The result is a monic
%   polynomial as well.

%   L.Ljung 2-10-92
%   Copyright 1986-2000 The MathWorks, Inc.
%   $Revision: 1.5 $  $Date: 2000/06/15 11:40:00 $

if length(A)==1,B=A;return,end
v = roots(A); ind=(abs(v)>eps);
vs = 0.5*(sign(abs(v(ind))-1)+1);
v(ind) = (1-vs).*v(ind) + vs./ (conj(v(ind)));
B = poly(v);
if ~any(imag(A))
  B = real(B);
end
