New function to calculate speed