Script to find best EMG period