Add function for auto threshold calculation.