Re: [time-nuts] exponential+linear fit
Jim, most if not all fitting strategies make use of an assumption concerning the underlying model. For those who are not sure what the underlying model is this one http://creativemachines.cornell.edu/eureqa is the hottest tool that I have ever seen. Give it a try. Best regards Ulrich -Ursprungliche Nachricht- Von: time-nuts-boun...@febo.com [mailto:time-nuts-boun...@febo.com] Im Auftrag von Jim Lux Gesendet: Freitag, 4. Oktober 2013 19:38 An: Discussion of precise time and frequency measurement Betreff: [time-nuts] exponential+linear fit 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. ___ 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. ___ 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.
Re: [time-nuts] exponential+linear fit
very cool Am 07.10.2013 09:46, schrieb Ulrich Bangert: Jim, most if not all fitting strategies make use of an assumption concerning the underlying model. For those who are not sure what the underlying model is this one http://creativemachines.cornell.edu/eureqa is the hottest tool that I have ever seen. Give it a try. Best regards Ulrich -Ursprungliche Nachricht- Von: time-nuts-boun...@febo.com [mailto:time-nuts-boun...@febo.com] Im Auftrag von Jim Lux Gesendet: Freitag, 4. Oktober 2013 19:38 An: Discussion of precise time and frequency measurement Betreff: [time-nuts] exponential+linear fit 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. ___ 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. ___ 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. ___ 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.
Re: [time-nuts] exponential+linear fit
Proposing a random fitting with various curves without an underlying physical (e.g. Eureqa) model seems... odd. That's more voodoo engineering/science than anything real. It doesn't surprise me that computer scientists would propose that as an approach to data, making it even more inappropriate. Having well-versed engineers and physical scientists looking at curves and striving to understand the various features with underlying well-understood and used physical models (including abnormalities in measurements), that seems appropriate. The originally proposed model of long term linear drift trend plus exponential decay of initial thermal conditions is very well understood and accepted. On Mon, Oct 7, 2013 at 3:46 AM, Ulrich Bangert df...@ulrich-bangert.dewrote: Jim, most if not all fitting strategies make use of an assumption concerning the underlying model. For those who are not sure what the underlying model is this one http://creativemachines.cornell.edu/eureqa is the hottest tool that I have ever seen. Give it a try. Best regards Ulrich -Ursprungliche Nachricht- Von: time-nuts-boun...@febo.com [mailto:time-nuts-boun...@febo.com] Im Auftrag von Jim Lux Gesendet: Freitag, 4. Oktober 2013 19:38 An: Discussion of precise time and frequency measurement Betreff: [time-nuts] exponential+linear fit 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. ___ 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. ___ 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. ___ 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.
Re: [time-nuts] exponential+linear fit
On 10/7/13 6:03 AM, Tim Shoppa wrote: Proposing a random fitting with various curves without an underlying physical (e.g. Eureqa) model seems... odd. That's more voodoo engineering/science than anything real. It doesn't surprise me that computer scientists would propose that as an approach to data, making it even more inappropriate. Having well-versed engineers and physical scientists looking at curves and striving to understand the various features with underlying well-understood and used physical models (including abnormalities in measurements), that seems appropriate. The originally proposed model of long term linear drift trend plus exponential decay of initial thermal conditions is very well understood and accepted. however, sometimes, looking to see what else fits might lead to insight into what is going on inside the box, when you don't have any information. In general, though, I agree with you. Every year at the International Science and Engineering Fair (and at the local and regional fairs before it), I see people fitting a straight line to data that is fundamentally not linear (e.g. RF signal strength vs distance, or aerodynamic drag vs velocity, or speed of sound vs temperature) I can sort of forgive trying to use a polynomial fit for something for which the underlying physics says something different; especially if there's no other choice. Square roots are a particular problem and pop up surprisingly often: vterminal = sqrt(2*accel*distance), and are not modeled well by a polynomial. However, the Excel plot with the linear regression, giving coefficients out to 5 digits and R^2 the same, is just inappropriate; particularly at the ISEF level. ___ 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.
Re: [time-nuts] exponential+linear fit
I agree a fit to an equation that has no physical meaning is a bit spurious. You can fit almost anything to a polynomial, but it doesnt mean that the coefficients mean anything or that an interpolation between data points is even sensible!! I have been the victim of a clever maths graduate (with no physics knowledge!) Alan G3NYK - Original Message - From: Tim Shoppa tsho...@gmail.com To: Discussion of precise time and frequency measurement time-nuts@febo.com Sent: Monday, October 07, 2013 2:03 PM Subject: Re: [time-nuts] exponential+linear fit Proposing a random fitting with various curves without an underlying physical (e.g. Eureqa) model seems... odd. That's more voodoo engineering/science than anything real. It doesn't surprise me that computer scientists would propose that as an approach to data, making it even more inappropriate. Having well-versed engineers and physical scientists looking at curves and striving to understand the various features with underlying well-understood and used physical models (including abnormalities in measurements), that seems appropriate. The originally proposed model of long term linear drift trend plus exponential decay of initial thermal conditions is very well understood and accepted. On Mon, Oct 7, 2013 at 3:46 AM, Ulrich Bangert df...@ulrich-bangert.dewrote: Jim, most if not all fitting strategies make use of an assumption concerning the underlying model. For those who are not sure what the underlying model is this one http://creativemachines.cornell.edu/eureqa is the hottest tool that I have ever seen. Give it a try. Best regards Ulrich -Ursprungliche Nachricht- Von: time-nuts-boun...@febo.com [mailto:time-nuts-boun...@febo.com] Im Auftrag von Jim Lux Gesendet: Freitag, 4. Oktober 2013 19:38 An: Discussion of precise time and frequency measurement Betreff: [time-nuts] exponential+linear fit 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. ___ 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. ___ 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. ___ 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. ___ 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.
Re: [time-nuts] exponential+linear fit
Which reminds me, there is a nifty tool called fityk that I tend to use just to view graphs, but has a rather nice set of routines to do various fits to various curves. Cheers, Magnus On 10/07/2013 09:46 AM, Ulrich Bangert wrote: Jim, most if not all fitting strategies make use of an assumption concerning the underlying model. For those who are not sure what the underlying model is this one http://creativemachines.cornell.edu/eureqa is the hottest tool that I have ever seen. Give it a try. Best regards Ulrich -Ursprungliche Nachricht- Von: time-nuts-boun...@febo.com [mailto:time-nuts-boun...@febo.com] Im Auftrag von Jim Lux Gesendet: Freitag, 4. Oktober 2013 19:38 An: Discussion of precise time and frequency measurement Betreff: [time-nuts] exponential+linear fit 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. ___ 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. ___ 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. ___ 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.
Re: [time-nuts] exponential+linear fit
On 10/7/13 2:44 PM, Magnus Danielson wrote: Which reminds me, there is a nifty tool called fityk that I tend to use just to view graphs, but has a rather nice set of routines to do various fits to various curves. gnuplot's not bad, either.. you define a function f(x) and the free parameters, define some starting values, kick off the fit, and let it roll. so I did f(x) = a + b*x + c*exp(d*x) with some starting values picked by eye and it did an ok job with the fit. It is NOT speedy though.. It's an iterative solution and takes a good 30 seconds on my macbook air to fit the 6000 data points I have. ___ 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.
Re: [time-nuts] exponential+linear fit
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.
Re: [time-nuts] exponential+linear fit
On 10/5/13 3:44 AM, Magnus Danielson wrote: And I want to do it quickly on a slow processor. ... and a simple high-pass filter won't do it for you? I suppose so..I'll have to fool with that. A high pass filter would definitely take out the DC and linear terms, but I'm not so sure about the exponential transient. (OTOH, as I look at more of the data, maybe I just lop off the first chunk of data with some empirical knowledge) Can you store all samples in memory and iterate over them? Yes.. it can be acausal. It's sort of like looking at frequency or ADEV data, removing the aging, and trying to see the fluctuations due to room temperature variation. ___ 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.
Re: [time-nuts] exponential+linear fit
On 10/05/2013 04:48 PM, Jim Lux wrote: On 10/5/13 3:57 AM, Magnus Danielson wrote: On 10/05/2013 01:03 AM, Jim Lux wrote: On 10/4/13 2:54 PM, Alan Melia wrote: Jim it may not be helpful but had you thoughtof expanding the exponential as the first few terms of an infinite series to see if it simplifies fitting? I'll try attaching a plot of some sample data. Oh, I/Q data, in that case recording the state of your tracking loop helps a lot. Also, the rate of your exponential should be fairly well known, so you could do a linear least square with that. It's IQ but not from a tracking loop.. The underlying physics is a turn on transient as it comes to temperature (with gain/phase variation) superimposed on a longer term linear trend. Ah, OK. And it occurs to me that fitting more polynomial terms (although one can represent exp(x)+kx with a polynomial) runs the risk of removing the data (the variations in the I/Q), while constraining the fit to an exp(-kt) means that the transient starts at the beginning. You will reduce your degrees of freedom with the amount of polynomial terms you estimate and remove from the data. Your Pade approximation to a+kx+b*exp(c*x) of say three terms of exp will consume 5 degrees of freedom, but if you have thousands of samples you can live with it for many uses. What kind of measure do you want to extract here really? Noise-power? 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.
Re: [time-nuts] exponential+linear fit
Hi Jim, On 10/05/2013 04:52 PM, Jim Lux wrote: On 10/5/13 3:44 AM, Magnus Danielson wrote: And I want to do it quickly on a slow processor. ... and a simple high-pass filter won't do it for you? I suppose so..I'll have to fool with that. A high pass filter would definitely take out the DC and linear terms, but I'm not so sure about the exponential transient. (OTOH, as I look at more of the data, maybe I just lop off the first chunk of data with some empirical knowledge) The transient will make it through the filter, and if you can waste the first bunch, a simple one or two-pole high-pass filter will cost you brilliantly little processing to reduce the linear trend to essentially nothing. Can you store all samples in memory and iterate over them? Yes.. it can be acausal. OK. Good. It's sort of like looking at frequency or ADEV data, removing the aging, and trying to see the fluctuations due to room temperature variation. Ah. Then after the initial transient, all you want to do is estimate the drift term and remove it from your data. That's not too hard to do with a simple least square algorithm. I've also made variants of ADEV processing that accumulates values such that the linear drift can be taken out of the ADEV without re-iterating, but in that case the Hadamard does it too. When doing a least square you get frequency and drift parameters and can then get a reduced sample-set for ADEV and friends to chew on. You only need to estimate the exponential decay if your samples are precious and you need to get those early samples. 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.
Re: [time-nuts] exponential+linear fit
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 2N'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 jim...@earthlink.net 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.8000802@earthlink.**net524efcff.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. 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@febo.com To unsubscribe, go to https://www.febo.com/cgi-bin/** mailman/listinfo/time-nutshttps://www.febo.com/cgi-bin/mailman/listinfo/time-nuts and follow the instructions there. ___ 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.
Re: [time-nuts] exponential+linear fit
On 10/5/13 8:30 AM, Magnus Danielson wrote: Hi Jim, On 10/05/2013 04:52 PM, Jim Lux wrote: On 10/5/13 3:44 AM, Magnus Danielson wrote: And I want to do it quickly on a slow processor. ... and a simple high-pass filter won't do it for you? I suppose so..I'll have to fool with that. A high pass filter would definitely take out the DC and linear terms, but I'm not so sure about the exponential transient. (OTOH, as I look at more of the data, maybe I just lop off the first chunk of data with some empirical knowledge) The transient will make it through the filter, and if you can waste the first bunch, a simple one or two-pole high-pass filter will cost you brilliantly little processing to reduce the linear trend to essentially nothing. Can you store all samples in memory and iterate over them? Yes.. it can be acausal. OK. Good. It's sort of like looking at frequency or ADEV data, removing the aging, and trying to see the fluctuations due to room temperature variation. Ah. Then after the initial transient, all you want to do is estimate the drift term and remove it from your data. That's not too hard to do with a simple least square algorithm. yes.. I've also made variants of ADEV processing that accumulates values such that the linear drift can be taken out of the ADEV without re-iterating, but in that case the Hadamard does it too. When doing a least square you get frequency and drift parameters and can then get a reduced sample-set for ADEV and friends to chew on. You only need to estimate the exponential decay if your samples are precious and you need to get those early samples. Exactly... It's a fairly simple model. I'll have to look at a bunch of data sets and decide if the exponential part is something I can just chop off. In the previous system, the time in the exponential part was a significant fraction of the total data set, but in this one it seems to be a lot faster. Cursory estimation by eye makes it look like out of the 2000 samples in the plot, the transient has died out by 200 samples. Since the typical data epoch is 10s of thousands of samples, losing the first 200 is no big deal. That's why I was loathe to leap in and turn the full power of Matlab nonlinear fits into it. ___ 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.
Re: [time-nuts] exponential+linear fit
Ok, here is an approach to the iterative least-squares fit: F(t) = k1 + k2*t + k3*exp(k4*t) L = Sum( [yi - F(ti)] ^2 ) So least square for each parameter: dL/dk = 0 The summing nomenclature is rather awkawrd in ascii, so I'll use T = Sum(ti) T^2 = Sum(ti^2) E = Sum( exp(k4*ti) ) TE = Sum( ti*ext(k4*ti) ) E^2 = Sum( exp(2*k4*ti) ) etc for Y, TY, EY, TEY, TE^2 dL/dk1 - N*k1 + T*k2 + E* k3 = Y dL/dk2 - T*k1 + T^2*k2 + TE* k3 = TY dL/dk3 - E*k1 + TE*k2 + E^2* k3 = EY dL/dk4 - TE*k1 + T^2E*k2 + TE^2* k3 = TEY The only problem is that k4 is stuck in that E term. I use the last 3 equations for solve for k1, k2 and k3 given the data and k4 then use Newton-Raffson's method to fin an iterative solution for k4. E.g. Let X=[k1,k2,k3], B=[TY,EY,TEY] and A= [ TT^2TE ] [ E TE E^2 ] [TE T^2E TE^2 ] Then solving A.X=B is easy for a given k4 Use the first equation N*k1+T*k2+E*k3=Y as G(k4) = N*k1+T*k3+E*k3-Y (=0 eventually) Newton's method needs dG/dk4 = k3*TE which we already solved for! Thus k4new = k4 - G(k4)/(k3*TE Use the new k4 to calculate E, E^2, ... then new k1,k2,k3. The advantage of this approach is that you are doing an iterative aproximation on only one parameter, with explicit calculation of the other parameters. Paul Alfille On Sat, Oct 5, 2013 at 11:18 AM, Magnus Danielson mag...@rubidium.dyndns.org wrote: On 10/05/2013 04:48 PM, Jim Lux wrote: On 10/5/13 3:57 AM, Magnus Danielson wrote: On 10/05/2013 01:03 AM, Jim Lux wrote: On 10/4/13 2:54 PM, Alan Melia wrote: Jim it may not be helpful but had you thoughtof expanding the exponential as the first few terms of an infinite series to see if it simplifies fitting? I'll try attaching a plot of some sample data. Oh, I/Q data, in that case recording the state of your tracking loop helps a lot. Also, the rate of your exponential should be fairly well known, so you could do a linear least square with that. It's IQ but not from a tracking loop.. The underlying physics is a turn on transient as it comes to temperature (with gain/phase variation) superimposed on a longer term linear trend. Ah, OK. And it occurs to me that fitting more polynomial terms (although one can represent exp(x)+kx with a polynomial) runs the risk of removing the data (the variations in the I/Q), while constraining the fit to an exp(-kt) means that the transient starts at the beginning. You will reduce your degrees of freedom with the amount of polynomial terms you estimate and remove from the data. Your Pade approximation to a+kx+b*exp(c*x) of say three terms of exp will consume 5 degrees of freedom, but if you have thousands of samples you can live with it for many uses. What kind of measure do you want to extract here really? Noise-power? 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. ___ 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.
Re: [time-nuts] exponential+linear fit
On 10/5/13 8:47 AM, Tim Shoppa wrote: 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 2N's and 555's, etc.) you have to do the fit on, then it's an interesting problem :-) In the future, more the latter than the former. 48 MHz ARM Cortex-M4, for instance. For now, though, yeah, it's on a not very fast PC (Windows Experience Rating around 2), but compiled matlab does it very quickly. But, given that sooner or later I'm going to be heading for a more resource constrained environment, or trying to FPGA it, I'm looking for simple algorithms to implement the simplified models. And, of course, I don't want to drag in all the libraries that one gets with Matlab,Octave,gnuplot, etc. They're great for figuring out what's going on and trying out the algorithms. ___ 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.
Re: [time-nuts] exponential+linear fit
Hi Jim, On 10/05/2013 05:47 PM, Jim Lux wrote: Ah. Then after the initial transient, all you want to do is estimate the drift term and remove it from your data. That's not too hard to do with a simple least square algorithm. yes.. OK. Then we are on the same page. I've also made variants of ADEV processing that accumulates values such that the linear drift can be taken out of the ADEV without re-iterating, but in that case the Hadamard does it too. When doing a least square you get frequency and drift parameters and can then get a reduced sample-set for ADEV and friends to chew on. You only need to estimate the exponential decay if your samples are precious and you need to get those early samples. Exactly... It's a fairly simple model. I'll have to look at a bunch of data sets and decide if the exponential part is something I can just chop off. In the previous system, the time in the exponential part was a significant fraction of the total data set, but in this one it seems to be a lot faster. Cursory estimation by eye makes it look like out of the 2000 samples in the plot, the transient has died out by 200 samples. Since the typical data epoch is 10s of thousands of samples, losing the first 200 is no big deal. That's why I was loathe to leap in and turn the full power of Matlab nonlinear fits into it. Indeed. I'll have some code that probably can do exactly what you want in plain C. Just need a few lines for the prepping of the model to suit the needs. Toss me a few datasets if you can. 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.
Re: [time-nuts] exponential+linear fit
Re: time-nuts Digest, Vol 111, Issue 21 On Sat, 05 Oct 2013 11:54:08 -0400, time-nuts-requ...@febo.com wrote: Message: 6 Date: Sat, 05 Oct 2013 08:53:52 -0700 From: Jim Lux jim...@earthlink.net To: time-nuts@febo.com Subject: Re: [time-nuts] exponential+linear fit Message-ID: 52503610.4040...@earthlink.net Content-Type: text/plain; charset=ISO-8859-1; format=flowed On 10/5/13 8:47 AM, Tim Shoppa wrote: 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 2N's and 555's, etc.) you have to do the fit on, then it's an interesting problem :-) In the future, more the latter than the former. 48 MHz ARM Cortex-M4, for instance. For now, though, yeah, it's on a not very fast PC (Windows Experience Rating around 2), but compiled matlab does it very quickly. But, given that sooner or later I'm going to be heading for a more resource constrained environment, or trying to FPGA it, I'm looking for simple algorithms to implement the simplified models. And, of course, I don't want to drag in all the libraries that one gets with Matlab,Octave,gnuplot, etc. They're great for figuring out what's going on and trying out the algorithms. There are lots of suitable subroutines available in Numerical Recipes in C by Press et al, that can be used as is, or as the starting point. http://apps.nrbook.com/c/index.html Joe Gwinn ___ 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.
Re: [time-nuts] exponential+linear fit
On 10/5/13 9:10 AM, Joseph Gwinn wrote: Re: time-nuts Digest, Vol 111, Issue 21 On Sat, 05 Oct 2013 11:54:08 -0400, time-nuts-requ...@febo.com wrote: Message: 6 Date: Sat, 05 Oct 2013 08:53:52 -0700 From: Jim Lux jim...@earthlink.net To: time-nuts@febo.com Subject: Re: [time-nuts] exponential+linear fit Message-ID: 52503610.4040...@earthlink.net Content-Type: text/plain; charset=ISO-8859-1; format=flowed On 10/5/13 8:47 AM, Tim Shoppa wrote: 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 2N's and 555's, etc.) you have to do the fit on, then it's an interesting problem :-) In the future, more the latter than the former. 48 MHz ARM Cortex-M4, for instance. For now, though, yeah, it's on a not very fast PC (Windows Experience Rating around 2), but compiled matlab does it very quickly. But, given that sooner or later I'm going to be heading for a more resource constrained environment, or trying to FPGA it, I'm looking for simple algorithms to implement the simplified models. And, of course, I don't want to drag in all the libraries that one gets with Matlab,Octave,gnuplot, etc. They're great for figuring out what's going on and trying out the algorithms. There are lots of suitable subroutines available in Numerical Recipes in C by Press et al, that can be used as is, or as the starting point. http://apps.nrbook.com/c/index.html Yes, I have that (and in FORTRAN, too).. It's not so much the implementation details (although efficient implementations are of use) as the general strategy. e.g. do a nonlinear iterative fit to find the 4 parameters of interest OR do some sort of sequential remove this then remove that ___ 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.
[time-nuts] exponential+linear fit
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. ___ 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.
Re: [time-nuts] exponential+linear fit
Hello, Jim, On Fri, 4 Oct 2013, Jim Lux wrote: 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. (...etc) The control estimation practice is to model such a disturbance as a response of LTI system to, in your particular case, (almost) deterministic excitation. Specifically, the exp() term is a response of 1st-order lowpass (1/(1+s*T). The k1+k2*t is a response of double cascaded integrator (1/s^2). If you need to fit the model to data, the inputs to the subsystems should be found (inverse filtration for simple systems, spectral factorization and inverse filtration for the more complicated ones). If you don't know the T, a greybox identification should be done in addition. What is interesting: the model and often also the fit methods are the same either for the deterministic signal (such as your y(t)), as well as for the stochastic signals, like colored noise. Following statements from optimal estimation theory, both white noise as well as Dirac (delta) function share some common properties w.r.t. to LTI system description, and it is enoiugh to describe (and fit, estimate, etc.) then with the same tools. (Of course, this is limited to the linear system domain, L2 criterions etc.) Similar matter of clock drifts have been briefly discussed in our recent paper, dealing with two-clock ensembling: Clock Composition by Wiener Filtering Illustrated on Two Atomic Clocks (M.Peca, V.Michalek, M.Vacek) http://rtime.felk.cvut.cz/~pecam1/eftf/ In case of interest, feel free to contact me directly. Best regards, Marek ___ 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.
Re: [time-nuts] exponential+linear fit
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. 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 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. Joe Gwinn ___ 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.
Re: [time-nuts] exponential+linear fit
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. 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@febo.com To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts and follow the instructions there.
Re: [time-nuts] exponential+linear fit
Hi Joe that sounds like a system I was thinking of suggesting to Jim. I wrote some iterative code on a time share bureau machine in the late60s. make a guess at kx values and let the prog spit out k values for a dk/dt minimum then chose another set of starters an see if it finishes in the same place. A given local minimum may not be the lowest. Its crude but very effective. My boss didnt believe it and employed a mathematician who did not understand the physics to get it wrong ! this was fitting to similar type equation an Arhennius equation (if I remembered how to spell him :-)) A friendly mathematician called it the BFI technique Alan G3NYK - Original Message - From: Joseph Gwinn joegw...@comcast.net To: time-nuts@febo.com Sent: Friday, October 04, 2013 9:18 PM Subject: Re: [time-nuts] exponential+linear fit 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. 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 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. Joe Gwinn ___ 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. ___ 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.
Re: [time-nuts] exponential+linear fit
Jim it may not be helpful but had you thoughtof expanding the exponential as the first few terms of an infinite series to see if it simplifies fitting? Alan G3NYK - Original Message - From: Jim Lux jim...@earthlink.net To: time-nuts@febo.com Sent: Friday, October 04, 2013 10:16 PM Subject: Re: [time-nuts] exponential+linear fit 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. 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@febo.com To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts and follow the instructions there. ___ 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.
Re: [time-nuts] exponential+linear fit
Dear Jim, 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. I think the LTI framework should work very well for that; easy fixpoint implementation etc. Since I am a space fan, I'd be happy to try my tools. Would you like to send me the data? 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. One example of such an estimator (working real-time), which I did in 2008: http://www.youtube.com/watch?v=Di4yG6ZRV3k Only the exp() term is missing here, the rest is same -- and besides the position and heading, it contains also 2nd order clock estimation -- similar way as in the GNSS. Best regards, Marek ___ 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.
Re: [time-nuts] exponential+linear fit (Joseph Gauthier)
You might like this free MATLAB toolbox: http://www.mathworks.com.au/matlabcentral/fileexchange/24443-slm-shape-language-modeling Once you figure out how to use it, it works very well for all types of fits. ___ 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.