stable adaptive threshold function