Automatic threshold calibration; e.g. threshold automatically adapts to ambient conditions or follows variation of input