HMM implementation based on Viterbi alghoritms