How do i calculate FWHM from Gaussian fitted curve??

조회 수: 80 (최근 30일)
Laurent Vaughan
Laurent Vaughan 2018년 6월 27일
댓글: Rik 2021년 7월 6일
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
Daniel Capellán Martín 2018년 12월 10일
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에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by