How to calculate FWHM on the graph
86 views (last 30 days)
Show older comments
mohd akmal masud
on 18 Jun 2023
Commented: Star Strider
on 19 Jun 2023
Dear All,
I have graph attached.
Anyone can help me to calculate the FWHM based on my graph attached?
0 Comments
Accepted Answer
Star Strider
on 18 Jun 2023
Try this —
LD1 = load('xstats.mat');
xstats = LD1.xstats
LD2 = load('ystats.mat');
ystats = LD2.ystats
F = openfig('graph.fig');
Lines = findobj(F, 'Type','Line');
x = Lines.XData;
y = Lines.YData;
wx = fwhm(x,y)
[wm,xr,hm] = myFWHM(x,y)
[ymax,idx] = max(y);
ymin = min(y);
figure
plot(x, y)
hold on
plot(xr, [1 1]*hm+ymin, '.-r')
hold off
grid
text(x(idx), hm+ymin, sprintf('FWHM = %.3f',wm), 'Horiz','center', 'Vert','bottom')
% ylim([min(y) max(y)])
function [width,xr,hm] = myFWHM(x, y)
p1 = polyfit(x([1 end]), y([1 end]), 1);
y_dtrnd = y - polyval(p1,x);
[ymax,yidx] = max(y_dtrnd);
[ymin,xidx] = min(y_dtrnd);
idxrng = {1:yidx; yidx:numel(y)};
hm = (ymax-ymin)/2;
xr(1) = interp1(y_dtrnd(idxrng{1})-ymin, x(idxrng{1}), hm, 'linear');
xr(2) = interp1(y_dtrnd(idxrng{2})-ymin, x(idxrng{2}), hm, 'linear');
width = xr(2)-xr(1);
end
The .mat files do not appear to add any useful information. The ‘fwhm’ function does not appear to correct forr a non-zero baseline.
.
2 Comments
Star Strider
on 19 Jun 2023
The ‘wx’ value is the width that the ‘fwhm’ function calculates. It calculates from zero, not from the function minimum.
For the others, ‘wm’ is the width (FWHM) my function calculates, ‘xr’ are the width points it returns (the difference between them is ‘xm’), and ‘hm’ is the half-maximum value my function returns. (I use them in the plot and the text arguments.) My function uses the funciton minnimum, rather than zero, to calculate all the necessary values. The title of your Question refers to ‘on the graph’ so I assume you want them all plotted. I presented all of the necessary information on the plot.
I still do not know what ‘xstats’ and ‘ystats’ refer to, however my earlier Answer calculated the widths with respect to ‘cx’ and ‘cy’ as well as the figure data.
.
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!