[time-nuts] exponential+linear fit

Tim Shoppa tshoppa at gmail.com
Sat Oct 5 11:47:26 EDT 2013


How slow of a processor are you working with? A modern PC using a general
purpose graphing and fitting tool (e.g. gnuplot) will fit tens of thousands
of points in a fraction of a second.
http://people.duke.edu/~hpgavin/gnuplot.html

If you want to do this in your own code, there are lots of least-squares
fitting examples in every first year numerical analysis textbook in every
computer language ever written (I learned this in FORTRAN 4 naturally).
http://en.wikipedia.org/wiki/Least_squares

If you have hardware substantially more primitive (e.g. a PIC, a bag of
2N2222's and 555's, etc.) you have to do the fit on, then it's an
interesting problem :-)

Tim.


On Fri, Oct 4, 2013 at 5:16 PM, Jim Lux <jimlux at earthlink.net> wrote:

> On 10/4/13 1:18 PM, Joseph Gwinn wrote:
>
>> On Fri, 04 Oct 2013 14:30:40 -0400, time-nuts-request at febo.com wrote:
>>
>>> ------------------------------
>>>
>>> Message: 4
>>> Date: Fri, 04 Oct 2013 10:38:07 -0700
>>> From: Jim Lux <jimlux at earthlink.net>
>>> To: Discussion of precise time and frequency measurement
>>>         <time-nuts at febo.com>
>>> Subject: [time-nuts] exponential+linear fit
>>> Message-ID: <524EFCFF.8000802 at earthlink.**net<524EFCFF.8000802 at earthlink.net>
>>> >
>>> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>>>
>>> I'm trying to find a good way to do a combination exponential/linear fit
>>> (for baseline removal).  It's modeling phase for a moving source plus a
>>> thermal transient, so the underlying physics is the linear term (the
>>> phase varies linearly with time, since the velocity is constant) plus
>>> the temperature effect.
>>>
>>> the general equation is y(t) = k1 + k2*t + k3*exp(k4*t)
>>>
>>> Working in matlab/octave, but that's just the tool, I'm looking for some
>>> numerical analysis insight.
>>>
>>> I could do it in steps.. do a straight line to get k1 and k2, then fit
>>> k3& k4 to the residual; or fit the exponential first, then do the
>>> straight line., but I'm not sure that will minimize the error, or if it
>>> matches the underlying model (a combination of a linear trend and
>>> thermal effects) as well.
>>>
>>> I suppose I could do something like do the fit on the derivative, which
>>> would be
>>>
>>> y'(t) = k2 + k3*k4*exp(k4*t)
>>>
>>> Then solve for the the k1.  In reality, I don't think I care as much
>>> what the numbers are (particularly the k1 DC offset) so could probably
>>> just integrate (numerically)
>>>
>>> y'()-k2-k3*k4*exp(k4*t) and get my sequence with the DC term, linear
>>> drift, and exponential component removed.
>>>
>>>
>>> The fear I have is that differentiating emphasizes noise.
>>>
>>
>> How many measured data points do you have?  If you have enough data,
>> you can use the MatLab nlinfit() (nonlinear fit) function to fit the
>> data directly to the y(t) equation.
>>
>
>
> I'm removing a slowly varying bias term from fairly noisy data.  Maybe
> several 10s of thousands of data points,
> And I want to do it quickly on a slow processor.
>
>
>
>
>
>> Because nlinfit uses a least-squares approach, and there are many
>> coefficients to be found, a reasonable starting point is required.  The
>> fit on the derivative, while probably too noisy to yield a useful final
>> answer, would be one way to get some of the initial values.
>>
>
> I've done that and it works.. but I'm looking for a more "basic" sort of
> approach, given that I actually know something about the underlying model.
>
>
>
>> I did just this recently, fitting a skew gaussian pdf to a histogram,
>> using rough mean, standard deviation, and skewness computed from the
>> histogram to seed nlinfit.  The mean, standard deviation, and skewness
>> computed from the histogram are famously inaccurate if there is
>> significant skew, but it was still good enough to keep nlinfit from
>> getting lost.
>>
>>
>
>
> ______________________________**_________________
> time-nuts mailing list -- time-nuts at febo.com
> To unsubscribe, go to https://www.febo.com/cgi-bin/**
> mailman/listinfo/time-nuts<https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts>
> and follow the instructions there.
>


More information about the time-nuts mailing list