how to find out full width at half maximum from this graph

236 views (last 30 days)
  3 Comments
parry sharma
parry sharma on 1 Nov 2016
Edited: parry sharma on 1 Nov 2016
i am new to matlab .that graph wrongly generated by me in matlab. 1) previous chart was mistakely uploaded actual graph i am attached now, Is in this graph i have to first smooth data then how please tell me. 2) but smoothing of data result in average of data that part so this may make effect on my experiment or not. 3)after smotthing my experiment data is valid or not, 4) to find out FWHM, i am using formula is Dmax-Dmin/2 at gradient region but how to find that gradient region with help of matlab and then compute this
Image Analyst
Image Analyst on 1 Nov 2016
OK, I've modified my answer below to take into account that your FWHM value is not based on the max but based on being between the min and the max.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 1 Nov 2016
Edited: Image Analyst on 24 Aug 2018
Use max():
% Find the half max value.
halfMax = (min(data) + max(data)) / 2;
% Find where the data first drops below half the max.
index1 = find(data >= halfMax, 1, 'first');
% Find where the data last rises above half the max.
index2 = find(data >= halfMax, 1, 'last');
fwhm = index2-index1 + 1; % FWHM in indexes.
% OR, if you have an x vector
fwhmx = x(index2) - x(index1);
  22 Comments
SP
SP on 31 Jul 2021
Edited: SP on 31 Jul 2021
@Image Analyst Thank you, sir. I understand about the concept of linear indexes from your explanation. But I did the code like this:
vq2 = resample(x_ccd,100,1);
for kkkkkk = 1:30
halfMax = 0.5; % Set FWHM at 0.30
vq1(kkkkkk,:) = resample(IFFT_hologram_bf_NM(kkkkkk,:),100,1);
% Find where the data first drops below half the max.
index1 = find(vq1(kkkkkk,20000:35000) >= halfMax, 1, 'first');
% Find where the data last rises above half the max.
index2 = find(vq1(kkkkkk,:) >= halfMax, 1, 'last');
xx1 = vq2(index1); %find the position in mm
xx2 = vq2(index2); %find the position in mm
fwhm(kkkkkk,:) = xx2-xx1;
end
I did for loop that the literation will be calculate from row-by-row. Even I difined kkkkkk as the literation of for loop then I limited the range of x axis array (20000:35000), but the values of index1 and index2 isn't calculated correctly. The reason that I limited (kkkkkk,20000:35000) because I don't want to calculate at the two red circles. But if I define like this:
index1 = find(vq1(kkkkkk,:) >= halfMax, 1, 'first');
or
index1 = find(vq1(kkkkkk,1:62900) >= halfMax, 1, 'first'); (the number array of vq1 = 62900 arrays)
it can calculated index1 and index2 correctly. May you suggest about this problem to me, sir?
Image Analyst
Image Analyst on 31 Jul 2021
You either need to just add in the offset you searched from, like 20,000 to the index,
index1 = find(vq1(kkkkkk,20000:35000) >= halfMax, 1, 'first');
index1 = index1 + 19999; % Get index relative to the original length of the vector, not the cropped length.
or just mask out the stuff you don't want so it's not found
vq1(kkkkkk, 1:19999) = -inf;
vq1(kkkkkk, 35001:end) = -inf;
index1 = find(vq1(kkkkkk,20000:35000) >= halfMax, 1, 'first');

Sign in to comment.

More Answers (2)

Maks
Maks on 24 Aug 2018
Edited: Maks on 24 Aug 2018
It should be "more or equal" for the first index: index1 = find(data >= halfMax, 1, 'first');
  3 Comments
Muhammad  Basit
Muhammad Basit on 9 Jul 2021
Hi, Could you please tell me whether the signs of >= should be on both indexes or for index2 it should be <=. Using your code, I'm not being able to find the correct answers.
Image Analyst
Image Analyst on 11 Jul 2021
@Muhammad Basit, I don't understand what you're asking. What sign? The code is the way it should be. If it doesn't work for your data, then give us your data and we'll fix it.

Sign in to comment.


Xiaomeng Gao
Xiaomeng Gao on 29 Dec 2021
This would be limited by available sample points. For example, if major peak has only 3 sample points, but it's neighboring peak is above half of max, then the neighbouring peak can be mistaken as first point that cross half max, potentially widening the width.

Tags

Community Treasure Hunt

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

Start Hunting!