# What is the most efficient and flexible algorithm to find constant term in a function

Suppose we have a discrete function which domain and codomain are both integers. For example, that function could be a signal from an ADC. In my case it is digitized signal from photomultiplier (see picture below). That signal have a baseline which represents the reference of the signal.

My analysis is very dependent on fine calculation of the baseline. So I am trying to implement an algorithm to determine position of the constant term in my signal. What is your ideas about my task?

I could just take several points in the tail of a signal and calculate the mean (which is in accordance with least square method):

But there is a problem of using this method when the signal is as follows: