modified hsmm_sim.m