How to calculate FWHM on the graph

86 visualizaciones (últimos 30 días)
mohd akmal masud
mohd akmal masud el 18 de Jun. de 2023
Comentada: Star Strider el 19 de Jun. de 2023
Dear All,
I have graph attached.
Anyone can help me to calculate the FWHM based on my graph attached?

Respuesta aceptada

Star Strider
Star Strider el 18 de Jun. de 2023
Try this —
LD1 = load('xstats.mat');
xstats = LD1.xstats
xstats = struct with fields:
min: 0 max: 24.3294 mean: 12.1647 median: 12.1647 mode: 0 std: 7.4434 range: 24.3294
LD2 = load('ystats.mat');
ystats = LD2.ystats
ystats = struct with fields:
min: 496 max: 3189 mean: 1.3102e+03 median: 857 mode: 498 std: 933.9319 range: 2693
F = openfig('graph.fig');
Lines = findobj(F, 'Type','Line');
x = Lines.XData;
y = Lines.YData;
wx = fwhm(x,y)
Pulse Polarity = Positive Pulse is Impulse or Rectangular with 2 edges
wx = 8.0080
[wm,xr,hm] = myFWHM(x,y)
wm = 6.9718
xr = 1×2
9.0430 16.0148
hm = 1.3460e+03
[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 comentarios
mohd akmal masud
mohd akmal masud el 19 de Jun. de 2023
tahnk you @Star Strider, I think the FWHM =6.972 is correct.
But what is the meaning of value below:
wx = 8.0080
wm = 6.9718
xr = 1×2
9.0430 16.0148
hm = 1.3460e+03
Star Strider
Star Strider el 19 de Jun. de 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.
.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by