function [simulated_hidden_path]=simulating_hidden_states(observation,transmat,emmision,alpha1)
D=[5 8  11  14  17 20];
T=length(observation);
Q=6;
simulated_hidden_path=[];
P=zeros(21,21,T);
%[alpha1]=compute_alpha(observation,emmision,transmat);
for t=2:T
    for r=2:(3*Q+3)
         for s=1:(3*Q+3)
             if ((s==5)||(s==8)||(s==11)||(s==14)||(s==17)||(s==20)||(s==21))
               P(r,s,t)=alpha1(r,t)*transmat(r,s);
             else
               P(r,s,t)=alpha1(r,t-1)*transmat(r,s)*emmision(s,observation(t));
             end
         end
        end
 
      P(:,:,t)=P(:,:,t)./sum(sum(P(:,:,t)));
end
column=alpha1(:,T);
[sim]=generate_hidden_variable(column);
simulated_hidden_path=[sim , simulated_hidden_path];  
while ((sim==D(1))||(sim==D(2))||(sim==D(3))||(sim==D(4))||(sim==D(5))||(sim==D(6)))
      column=P(:,sim,T);
      [sim]=generate_hidden_variable(column);
      simulated_hidden_path=[sim , simulated_hidden_path];
 end    
for t=(T-1):-1:1
    column=P(:,sim,t+1);
    [sim]=generate_hidden_variable(column);
    simulated_hidden_path=[sim , simulated_hidden_path];
    while ((sim==D(1))||(sim==D(2))||(sim==D(3))||(sim==D(4))||(sim==D(5))||(sim==D(6)))
      column=P(:,sim,t+1);
      [sim]=generate_hidden_variable(column);
      simulated_hidden_path=[sim , simulated_hidden_path];
    end    
end
 if ((simulated_hidden_path(1)==2)||(simulated_hidden_path(1)==3)||(simulated_hidden_path(1)==5))
       simulated_hidden_path=[1,simulated_hidden_path];
  elseif ((simulated_hidden_path(1)==4)||(simulated_hidden_path(1)==6))
       simulated_hidden_path=[1,5,simulated_hidden_path];
  elseif ((simulated_hidden_path(1)==7)||(simulated_hidden_path(1)==9))
       simulated_hidden_path=[1,5,8,simulated_hidden_path];
  elseif ((simulated_hidden_path(1)==10)||(simulated_hidden_path(1)==12))
       simulated_hidden_path=[1,5,8,11,simulated_hidden_path];
  elseif ((simulated_hidden_path(1)==13)||(simulated_hidden_path(1)==15))
       simulated_hidden_path=[1,5,8,11,14,simulated_hidden_path];
  elseif ((simulated_hidden_path(1)==16)||(simulated_hidden_path(1)==18))
       simulated_hidden_path=[1,5,8,11,14,17,simulated_hidden_path];
  elseif ((simulated_hidden_path(1)==19))
       simulated_hidden_path=[1,5,8,11,14,17,20,simulated_hidden_path];
 end

 if ((simulated_hidden_path(end)==2))
       simulated_hidden_path=[simulated_hidden_path,5,8,11,14,17,20,21];
 elseif ((simulated_hidden_path(end)==3)||(simulated_hidden_path(end)==4)||(simulated_hidden_path(end)==5))
       simulated_hidden_path=[simulated_hidden_path,8,11,14,17,20,21];
 elseif ((simulated_hidden_path(end)==6)||(simulated_hidden_path(end)==7)||(simulated_hidden_path(end)==8))
       simulated_hidden_path=[simulated_hidden_path,11,14,17,20,21];
 elseif ((simulated_hidden_path(end)==9)||(simulated_hidden_path(end)==10)||(simulated_hidden_path(end)==11))
       simulated_hidden_path=[simulated_hidden_path,14,17,20,21];
 elseif ((simulated_hidden_path(end)==12)||(simulated_hidden_path(end)==13)||(simulated_hidden_path(end)==14))
       simulated_hidden_path=[simulated_hidden_path,17,20,21];
 elseif ((simulated_hidden_path(end)==15)||(simulated_hidden_path(end)==16)||(simulated_hidden_path(end)==17))
       simulated_hidden_path=[simulated_hidden_path,20,21];
 elseif ((simulated_hidden_path(end)==18)||(simulated_hidden_path(end)==19)||(simulated_hidden_path(end)==20))
       simulated_hidden_path=[simulated_hidden_path,21];
 end
       

