I think this functionality is similar to robot.m (robot has a defined threshold >40 though)