function [w]=binary_markov()
p = 0.9;
N = 200;
w0 = rand(1) >= 0.5;
a = 0;
b = 1;

w= a* ones(1,N);
w(1)=w0;

u = rand(N,1);
dec = p >=u;

figure(1);
subplot(2,1,1);
stem(1:N,dec);
xlabel('Discrete Time')
title('Bernoulli Sequence');

for i = 2:N
    if dec(i) == 0;
        w(i) = w(i-1);
    else
        if w(i-1)==a;
            w(i)=b;
        else
            w(i)=a;
        end
    end
    subplot(2,1,2);
    stem(1:N,w);
    title('Markov sequence with memory')
    xlabel('discrete time')
    ylabel('level')
end