Fall detection algorithm