function  [X,t]=rlsim(A,b,y)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%  function  X=rlsim(A,b,y)
%
%  Simulates  x_n = A x_(n-1) + b y_n
%
%  for complex A,b,y
%  and generates the matrix of the state evolution
%
%  X = [x_0 x_1 ... x_N]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

y=y(:);
rA=real(A); iA=imag(A);
rb=real(b); ib=imag(b);
ry=real(y); iy=imag(y);

AA=[rA -iA; iA rA];
bb=[rb -ib; ib rb];
yy=[ry iy];

sys=ss(AA,bb,eye(size(AA)),zeros(size(bb)),-1);

t=0:length(yy)-1;
xx=lsim(sys,yy,t,zeros(length(AA),1));

X=xx(:,1:length(A))+j*xx(:,length(A)+1:length(AA));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Tryphon Georgiou (May 9, 2000)
