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!