How to calculate FWHM on the graph
86 次查看(过去 30 天)
显示 更早的评论
Dear All,
I have graph attached.
Anyone can help me to calculate the FWHM based on my graph attached?
0 个评论
采纳的回答
Star Strider
2023-6-18
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 个评论
Star Strider
2023-6-19
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.
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!