Code for motion tracking of handheld medical probe