Minimizing the FWHM of a Gaussian using fmincon
Afficher commentaires plus anciens
Hi there,
I am trying to write some code which alters the proportions in which several line profiles are combined as to minimize the FWHM of a Gaussian fit to the resultant profile. I managed to get it working but it was slightly messy and unconvincing, so I've been retrying.
From my code below, I use values of v (a vector containing four numbers) as coefficients for combining five images. I then take a linear profile across the image from a pre-defined region and perform a Gaussian fit to this profile (the fit function 'f' is the gauss1 fit modified to have a y-offset). I then calculate the FWHM of the fitted Gaussian.
What I want to do is vary the values of v to minimise the FWHM. I also want to make sure that the value of the minimized FWHM is not smaller than the value 'PixResol', so I used fmincon with what I thought to be appropriate constraints.
However, this is completely incorrect as I get the error message that the third argument in fmincon requires a four-element vector. As I understand it, this implies that fmincon is applying the constraints to the four different values of v. However, I don't care what values v takes, I am only concerned with the final value of the FWHM.
It is probably quite obvious that I am not at all experienced in minimization in Matlab, and I have been looking through the documentation for fmincon (and other minimizers) for help but have found none!
If anyone could at least point me in the right direction I would be incredibly grateful.
Many thanks,
Siân
[v,fval] = fmincon(@imfun, v0, -1, -PixResol);
function b = imfun(v)
c2 = v(1);
c3 = v(2);
c4 = v(3);
c5 = v(4);
im = im1 + c2*im2 + c3*im3 + c4*im4 + c5*im5;
for i = 1:length(im1Prof)
Y = im(yRange(i),xRange(i));
end
[fitobject gof] = fit(X, Y, f, ...
'Start', [max(Y) cent FWHMguess mean(Y(1:base))]);
coeffs = coeffvalues(fitobject);
FWHM = coeffs(3)*sqrt(2*log(2));
b = FWHM;
end
1 commentaire
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Mathematics dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!