thegooglecodearchive / guiqwt

Automatically exported from code.google.com/p/guiqwt
Other
0 stars 0 forks source link

Multi-peak fitting #39

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice to change the guifit() function so that it is convenient for 
multi-peak fitting. If I want to fit multiple peaks, e.g. 3 Gaussians, I would 
do it like that (adapted from the example in the docs):

def fit(x, params):
y0, A0, xc0, w0, A1, xc1, w1, A2, xc2, w2 = params
return y0 + A0*np.exp(-(x-xc0)**2/(2*w0**2)) + A1*np.exp(-(x-xc1)**2/(2*w1**2)) 
+ A2*np.exp(-(x-xc2)**2/(2*w2**2))

y0 = FitParam("Offset", 0., -10., 10.)
A0 = FitParam("Amplitude 0", 1., -10., 10.)
xc0 = FitParam("location 0", 2.5, 2., 5.)
w0 = FitParam("width 0", 1., -30., 30.)
A1 = FitParam("Amplitude 1", 1., -10., 10.)
xc1 = FitParam("location 1", 2.5, 2., 5.)
w1 = FitParam("width 1", 1., -30., 30.)
A2 = FitParam("Amplitude 2", 1., -10., 10.)
xc2 = FitParam("location 2", 2.5, 2., 5.)
w2 = FitParam("width 2", 1., -30., 30.)
params = [y0, A0, xc0, w0, A1, xc1, w1, A2, xc2, w2]
values = guifit(x, y, fit, params, xlabel="x", ylabel="Signal(x)")

Using guifit, the overall function, that was fitted, is now plotted. However, 
it would be nice to visualise the contributions of the individual peaks. So 
that you define fit=[fit1,fit2,fit2] with fit1=y0 + 
A0*np.exp(-(x-xc0)**2/(2*w0**2)) and the subfits are plotted additionally to 
the overall fit.

What version of the product are you using? On what operating system?

Version 2.1.6 under Linux

Original issue reported on code.google.com by warin...@gmx.net on 26 Nov 2012 at 4:57