Gaussian fitting, peak value, and FWHM measurement method.
15 views (last 30 days)
Show older comments
Hi I am suhan
I will attach the file.
I have 1 to 144 columns.
I want to draw 144 gaussian histograms fitting according to the column and find the positions of 144 FWHM and Peak.
There are a few more questions.
1. The x-axis range of all 144 columns should be -300 to 300.
2. I want to set bin size to 30. (Because the range of the x-axis is -300 to 300, there will be 21 bar graphs.)
3. If bin size changes, does FWHM and Peak value change a little?
help me please
2 Comments
Answers (1)
Ayush Anand
on 12 Jan 2024
Hi,
Here are the answers to the questions you asked above:
- To set the x-axis range to be from -300 to 300 for all histograms,you can use the "xlim" function.
- To set the bin size to 30 over the range of -300 to 300, you can calculate the number of bins required to cover this range with a bin width of 30 and then specify this number of bins as an argument in the "histfit" function.
- Yes, the FWHM and peak value might change slightly with different bin sizes because the histogram is an approximation of the underlying distribution, and changing the bin size changes this approximation.
Here's how you could modifiy the code for the same:
% M1 = readmatrix('D:/optical dat file/brightnix/20mm/7_MATLAB_20mm_diff_pivoted.txt');
% figure
% hold on
% Define the range and bin width
xRange = [-300, 300];
binWidth = 30;
% Calculate the number of bins that will cover the range with the given bin width
numBins = ceil((xRange(2)-xRange(1))/binWidth);
for k = 1:6
subplot(3,2,k)
% Use the specified number of bins and fit a normal distribution
hf{k} = histfit(M1(:,k), numBins, 'normal');
% Set the x-axis limits to range within -300 and 300
xlim(xRange)
% Find peaks and compute FWHM
[pks{k},locs{k},fwhm{k},prm{k}] = findpeaks(hf{k}(2).YData, hf{k}(2).XData, 'Annotate','extents', 'WidthReference','halfheight'); %Adding option WidthReference with halfheight so that the width value returned is FWHM
% Rest of the code remains same ...
end
% hold off
You can follow the links given below for more insights into this:
- https://www.mathworks.com/help/stats/histfit.html (Official documentation of the "histfit" function)
- https://www.mathworks.com/help/signal/ref/findpeaks.html (Official documentation of the "findpeaks" function)
- https://www.mathworks.com/matlabcentral/answers/741247-how-to-find-fwhm-for-each-peak (MATLAB Answer on how to find FWHM value for each peak)
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!