function [NEWA]=GetNewA(O,A,MI,SIGMA,Ptot,ALFA,BETA);

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

for i=2:(N-1),
  for j=2:(N-1),
    up=0; down=0;
    for t=1:(T-1),
      up=up+ALFA(i,t) * A(i,j) * ...
         normal (O(:,t+1), MI(:,j), SIGMA(:,j))*BETA(j, t+1); 
    end
    for t=1:T,
      down=down+ALFA(i,t) * BETA(i,t);
    end
    NEWA(i,j) = up / down;
  end
end

for j=2:(N-1),
    NEWA(1,j) = ALFA (j,1) * BETA(j,1) / Ptot;
end

down=0;
for i=2:(N-1),
%  for j=2:(N-1),             % Nejsem si jist, zda je ten cyklus navíc
    up=ALFA(i,T) * BETA (i,T);
    for t=1:T,
      down=down+ALFA(i,t) * BETA(i,t);
    end
    NEWA(i,N) = up / down;
%  end
end
