How do i calculate FWHM from Gaussian fitted curve??

59 次查看(过去 30 天)
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 个评论
Rik
Rik 2018-6-27
You can simply measure the distance between the half-maximum points. What code have you tried to do that?
Anton Semechko
Anton Semechko 2018-6-27
编辑:Anton Semechko 2018-6-27

Formula for FWHM of a Gaussian PSF:

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

请先登录,再进行评论。

回答(2 个)

Rik
Rik 2018-6-27
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 个评论
Gaëtan Poirier
Gaëtan Poirier 2021-7-6
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 2021-7-6
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.

请先登录,再进行评论。


Daniel Capellán Martín
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 个评论
umesh  birajdar
umesh birajdar 2019-3-13
above post is releted to this curve here selected the region according to the width of the curve.
image.JPG
Rik
Rik 2019-3-13
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by