%hmmgenerateseq.m
%Data generation 
function [state,DATA]=hmmgenerateseq(p11,p21,h11,h21,prior) 
DATA=[]; 
if(rand<prior) 
    state=1;
else
    state=2;
end
for i=1:1:500 
    if(state(i)==1) 
        if(rand<p11)
            state=[state 1];
        else
            state=[state 2];
        end
    else
        if(rand<p21) 
            state=[state 1]; 
        else
            state=[state 2];
        end
    end
if(state(i)==1)
    if(rand<h11) 
        DATA=[DATA 1]; 
    else
        DATA=[DATA 2];
    end
else if(rand<h21) 
        DATA=[DATA 1];
    else
        DATA=[DATA 2];
    end
end
end
end
