How do i calculate FWHM from Gaussian fitted curve??

65 vues (au cours des 30 derniers jours)
Laurent Vaughan
Laurent Vaughan le 27 Juin 2018
Commenté : Rik le 6 Juil 2021
I have fitted this Gaussian to my data nicely, however there doesn't seem to be an option or add-on in matlab to calculate the full width at half maximum for my function once saved. Is there a way to calculate this?
  2 commentaires
Rik
Rik le 27 Juin 2018
You can simply measure the distance between the half-maximum points. What code have you tried to do that?
Anton Semechko
Anton Semechko le 27 Juin 2018
Modifié(e) : Anton Semechko le 27 Juin 2018

Formula for FWHM of a Gaussian PSF:

 FWHM = 2*sqrt(2*ln(2))*s; % where s is the standard deviation 

Connectez-vous pour commenter.

Réponses (2)

Rik
Rik le 27 Juin 2018
More generally, the FWHM is the x-distance that describe the width of your curve halfway from the maximum to the baseline. Your fit is not a Gaussian, so you cannot use the formula. The code below shows how you can approximate the FWHM based on your data. You can input your raw data instead of your fit as well, but you need to be careful with noise that causes zero crossings or changes the maximum and minimum of your data.
%get the data back out of the figure
ax=gca;
x=ax.Children.XData;
y=ax.Children.YData;
%scale y-data, so the maximum is at 1 and the baseline is at 0
max_val=1;baseline=0;
y_scaled=y-min(y);
y_scaled=y_scaled/max(y_scaled);
y_scaled=y_scaled*(max_val-baseline)+baseline;
%zero cross index finder by Star Strider
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0);
%y_temp will cross 0 at half the maximum
y_temp=y_scaled-0.5*max(y_scaled);
idx=zci(y_temp);%get the indices of the two half-maximum points
FWHM=diff(x(idx));%get the difference between the corresponding x-values
hold on
plot(x(idx), y(idx),'k*-','DisplayName',sprintf('FWHM=%.1f',FWHM))
  3 commentaires
Gaëtan Poirier
Gaëtan Poirier le 6 Juil 2021
Hi,
This seems to work although the two half-maximum points are not located at the same point on the y-axis leading to the FWHM line not being flat. Is there anyway to fix this?
Thank you in advance!
Rik
Rik le 6 Juil 2021
That is likely due to the specific x-values of your samples. You will either have to resample so your exact points are included, or you need to fit a curve to your data so you can calculate the FWHM.

Connectez-vous pour commenter.


Daniel Capellán Martín
Daniel Capellán Martín le 10 Déc 2018
Hi, if you use the function fit, and type 'gauss2', 'gauss4', depending on how many gaussians you need to fit them to your data, when storing it in a variable, for example f, you can obtain the FWHM with f.c1, f.c2, ..., corresponding to the gaussian curve fitted that you are analysisng in order to obtain its width
  3 commentaires
umesh  birajdar
umesh birajdar le 13 Mar 2019
above post is releted to this curve here selected the region according to the width of the curve.
image.JPG
Rik
Rik le 13 Mar 2019
This is not a comment, but a separate question. If you decide to repost this as a question, consider the following two points:
Have a read here (or here for more general advice). It will greatly improve your chances of getting an answer.
If you already have a fit of you Gaussians, you can extract the standard deviation, which contains the complete information of whatever you could mean with 'width' in your specific context.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Descriptive Statistics dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by