function [ val ] = ViterbiHMM(V, U, T)
%     reduc=PCA(V, U);
    [~, frame]=size(V);
    [~, k]=size(T);
    T1=zeros(frame, k);
    T2=zeros(frame, k);
    %Initialisation
    T1(1,:)=1/k;
%     for i=1:frame
%         T1(reduc(1, i))=T1(reduc(1, i))+1;
%     end
%     T1(1,:)=T1(1,:)/sum(T1(1,:));
    
    for t=2:frame
        for i=1:k
            A=zeros(k,1);
            for j=1:k
                A(j)=T1(j, t-1)*T(i,j);
            end
            [a, b]=max(A);
            T1(i,j)=a;
            T2(i,j)=b;
        end
    end
    val=zeros(1,frame);
    [~,val(frame)]=max(T1(end,:));
    for t=frame:2
        val(t-1)=T2(t, val(t));
    end
end

