I would like to fit a fluorescent lifetime curve. These curves are given by the convolution of the instrument response function (IRF, assumed Gaussian) and a (multi) exponential decay:
Where G is the gaussian and F exponential decay. I have tried fitting this in python using lmfit.minimize, with the following functions:
def gaus(t, gamp, gwidth, gtoff):
i = gamp*math.exp(-(t-gtoff)**2/gwidth)
return i
def exp1(t, expamp, exptime, exptoff):
i = expamp*math.exp((t-exptoff)/(exptime))
return i
def func1(t, gamp, gwidth, gtoff, expamp1, exptime1, exptoff1):
i = [(scipy.integrate.quad(lambda Tpr: gaus((ti - Tpr), gamp, gwidth, gtoff)*exp1(ti, expamp1, exptime1, exptoff1), 0, ti))[0]
for ti in t]
return i
Where gaus defines the Gaussian instrument response function, exp1 is single exponential decay. func1 calculates the convolution between the two with scipy.integrate, the values it returns are used to calculate the difference between the fit and the data given a set of parameters:
def fitfunc(params, x, data):
..getting parameters part here..
values = func1(t, gamp, gwidth, toff, expamp1, exptime1, toff)
return values - data
result = lmfit.minimize(fitfunc, fit_params, args = (t, test))
Although this sort of works, the fitting process is very slow and has not yet given my any reasonable fits.
There are several approaches to circumvent the convolution process by using Fourier transforms or iterative deconvolution. Origin seems to know how to do it, but I am having trouble understanding the procedures.
As far as I can tell, iterative deconvolution works by deconvolving the signal with a guessed Gaussian function and then fitting the result, and then adjusting the Gaussian.
The Fourier transform approach would be based on the principle that convolution in real space corresponds to a multiplication in the Fourier domain, which would reduce computation time. I'm guessing that it would be Fourier transforming the signal, fitting that, and then Fourier transforming back.
I'd like some input on how to implement these methods in python numpy/scipy. The iterative deconvolution seems to be the easiest to do, so maybe I should start with that. On the other head, from what I've read, the Fourier method should be faster and more reliable. However, I have no idea how to perform fitting on the Fourier transformed result.