function [BETA]=GetBeta(O,A,MI,SIGMA);

[P,T]=size(O);
N=size(A,1);
BETA=zeros(N,T);
NORMB=zeros(1,T);

for i=2:N-1,
  BETA (i,T) = A(i,N);
end
NORMB(T)=max(BETA(:,T));
BETA(:,T) = BETA(:,T) / NORMB(T);

for t=(T-1):-1:1,
  for i=2:(N-1),
    suma =  0;
    for j=2:(N-1),
      suma=suma+ A(i,j)*normal (O(:,t+1), MI(:,j), SIGMA(:,j))*BETA(j, t+1);
    end
    BETA(i,t) = suma;
  end
  NORMB(t)=max(BETA(:,t));
  if t ~= 1,
    BETA(:,t) = BETA(:,t) / NORMB(t);
  end
end
  
for j=2:(N-1),
  suma=suma+ A(1,j)*normal (O(:,1), MI(:,j), SIGMA(:,j))*BETA(j,1);
end
BETA(1,1) = suma;
NORMB(1)=max(BETA(:,1));
BETA(:,1) = BETA(:,1) / NORMB(1);

PNB=zeros(1,T); 
for t=T:-1:1,
  PNB(t) = prod(NORMB(t:T));
end

BETA=ones(N,1) * PNB .* BETA;
