How to calculate FWHM on the graph
39 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
mohd akmal masud
il 18 Giu 2023
Modificato: Andrei
il 20 Ott 2025 alle 20:22
Dear All,
I have graph attached.
Anyone can help me to calculate the FWHM based on my graph attached?
0 Commenti
Risposta accettata
Star Strider
il 18 Giu 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 Commenti
Star Strider
il 19 Giu 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.
.
Più risposte (1)
Andrei
il 20 Ott 2025 alle 20:21
Modificato: Andrei
il 20 Ott 2025 alle 20:22
The findpeaks function in Signal Processing Toolbox can be used to determine the width (full width) of the detected peaks. By default, the peak widths (output w in the example below) are calculated at half prominence. You can also specify the reference height for peak width measurements, WidthReference name-value pair, as "halfprom" or "halfheight".
x = linspace(-5, 5, 101);
y = exp(-x.^2);
[pks,locs,w,p] = findpeaks(y,x)
0 Commenti
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

