function x=markovchain(nnodes)
% generates an observation of a 2-state Markov chain
% P(x(1)=0) = P(x(1)=1) = 0.5
% Transition matrix [ 0.99 0.01 ; 0.04 0.96 ]
x(1)=rand>0.5;
for n=2:nnodes
   if (x(n-1)==0)
      x(n)=rand<0.01;
   else
      x(n)=rand>0.04;
   end
end
plot(x)
axis([0 nnodes -2 3])
