Using HMM for trajectory analysis