using gradient descent to loccate baseline