--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/CA%2B7ESbrK9m2B2mh713y1n0LjC5sJhY_v3opJw_FpXKS_YoEqiQ%40mail.gmail.com.
Hi,Estimating the parameters of sine waves without resorting to fft is something I've been working with for a while. Here is a paper that proposes a simple, and in my opinion rather clever, method for estimating all the parameters: https://www.scribd.com/doc/14674814/Regressions-et-equations-integrales. I started translating the paper and implementing the methods it describes in a scikit-like format a while back, but had to take a long break. The aborted translation is here: https://scikit-guess.readthedocs.io/en/latest/appendices/reei/translation.html, and the code is here: https://github.com/madphysicist/scikit-guess. It's still very incomplete, but I'm hoping to finish it by mid next year. In the meantime, perhaps you will find it useful.At the same time, I'm working on a unique non-linear algorithm for estimating the frequency and phase of the wave. I will make it available to you as soon as I've completed the paper. The algorithm does not fit the amplitude of the wave at all. As a consequence, I've found that one of the better estimators for amplitude is std(y) * sqrt(2). It's much more robust against outliers than using min and max. Perhaps you could work out a similar metric from the IQR, which would probably be even more robust.
Apologies for the shameless (and premature) plugs of my ongoing projects.Could you please tag me on GitHub as @madphysicist when you submit the PR? I would be very interested to take a look at it.
--Regards,- JoeOn Thu, Nov 7, 2019, 1:33 PM Matt Newville <newv...@cars.uchicago.edu> wrote:--Hi Leonhard,On Thu, Nov 7, 2019 at 3:55 AM Leonhard Neuhaus <pyrpl.read...@gmail.com> wrote:I hope this is the right place to post this feature request:I have the impression a simple sinusoidal fit model like ``f(x) = a * sin(b * x + c) + d`` is missing from the collection of standard models in models.py. I believe it makes sense to try to add such a model here, as it is in general non-trivial to find good guesses. For example, while ``a``and ``d`` can be reasonably well guessed from the min/max of the data, and ``c`` might be inferred from an argmax or argmin of the data, I find that a good guess of ``b`` requires taking the argmax of the Fourier transformed data. I believe the place to develop a common solution for this problem is lmfit. I would be happy to contribute a pull-request that implements this, just wanted to make sure- that there is no such solution available already,- that the Fourier transform approach is the best one to get the frequency/period,- and that my pull-request would be appreciated.You're right that there is not any sort of periodic function, and there probably should be. I'd even suggest maybe having a damped sine wave would be a good idea. A PR for this would be great.I would suggest that giving more explicit names to the variables would be good, perhapsf(x) = amplitude * sin(frequency * x + phase_shift) + offset(and maybe even leave "offset" out as building a composite model of SineModel() + ConstantModel() would be easy).The `guess` method of a builtin models could be considered "nice to have" but optional. Still, I would agree that having a `guess` method would be doable and preferable here. Like you say, `amplitude` and `offset` (if retained) would be pretty easy (perhaps `amplitude=(data.max()-data.min())/2` and `offset=data.mean()`) while `frequency` and `phase_shift` could be more challenging. IMHO, using a FT for that would be fine -- we know that `scipy` is required, so using anything from `scipy` has to be OK. You might also be able to find the distance between a local max (with argmax) and the closest minimum to get the frequency, but I'm not sure how error-prone that would be for noisy signals.Anyway, yes a PR for this would be welcome!--Matt Newville
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/CA%2B7ESbrK9m2B2mh713y1n0LjC5sJhY_v3opJw_FpXKS_YoEqiQ%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/CAAa1KPbrvSUxPKFkomTev9Qic7o8Zsr91nk%3DVansN%3DLDXdCB%2BA%40mail.gmail.com.