On 10/04/2013 11:16 PM, Jim Lux wrote:
> On 10/4/13 1:18 PM, Joseph Gwinn wrote:
>> On Fri, 04 Oct 2013 14:30:40 -0400, time-nuts-requ...@febo.com wrote:
>>> ------------------------------
>>>
>>> Message: 4
>>> Date: Fri, 04 Oct 2013 10:38:07 -0700
>>> From: Jim Lux <jim...@earthlink.net>
>>> To: Discussion of precise time and frequency measurement
>>>     <time-nuts@febo.com>
>>> Subject: [time-nuts] exponential+linear fit
>>> Message-ID: <524efcff.8000...@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.
... and a simple high-pass filter won't do it for you?

Can you store all samples in memory and iterate over them?

Just trying to figure out your limits.

>
>
>
>>
>> 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.
Least-square do require you to know something about the underlying
model. If you can build the Jacobian, that helps.

Least-square isn't all that hard to do incremental, which means that
there is very little data to be held in memory compared to the
straight-forward way. You only need to hold the data-series in memory if
you need it for other purposes.

Cheers,
Magnus
_______________________________________________
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.

Reply via email to