Getting FWHM from distribution fitter

Hello,
Prefacing with the fact that I am very new to MATLAB. I have 10 distributions of data that look gaussian as they are supposed to. I have created histograms for each set and am set out to calculate the FWHMs - I have looked at some of the answers on here that haven't seemed to help, probably because I don't understand enough. I used the Distribution Fitter App to generate a curve with the "non-parametric' option because the "normal" option seemed to leave out a lot of the peak data. Attached is the photo of that.
1.) What I am hoping to do is calcluate the FWHM from the curve with your help if possible. (Possibly get the equation for the line and use that to find the FWHM?)
2.)If someone thinks there is a better solution to calculating the FWHM more appropriately for my data, please feel free to neglect the first request.
Some background since the question has been asked:
I used TOPAS (Tool for Particle Simulation) softward to get x and y data of protons that hit a "PhaseSpace", basically like holding a sheet of paper a few inches away from a small flashlight, where the photons are playing the role of protons for me, and I get the x and y locations of each particle. This makes a spot on my phasespace and the size of that spot changes with energy, called the spotprofile. As expected, more particles should be recorded near the center, and lessen as you move away from the center, creating a Gaussian distribution. I am looking to calculate the FWHM of each spot's distribution.

 Risposta accettata

Star Strider
Star Strider il 27 Set 2020
One way to get the FWHM is to use the findpeaks function. It may be ‘overkill’ for only one peak, however it should give you the result you want.

11 Commenti

Star Strider, thank you for such a quick response to my question. I will look into the MATLAB documentation on how to use findpeaks. I can see in there that it points out something like "half-prominence" which may just be what I need. Thank you and if I still can't understand it with the walk-through I might come back to this thread for more help. Thank you again very, very much.
As always, my pleasure!
Star Strider, I have tried the findpeaks and it outputs a bunch of what I think are the peaks? I have a lot of data in the histogram so there was a lot of output. Is there a way I can just get MATLAB to get the peak and FWHM of the non-parametric curve that is displayed in the photo in my question? Trying to use the findpeaks tool on the histogram seems to be my problem, I am more looking to make a Gaussian from my data and then use the findpeaks. Please let me know if what I am saying makes sense. Thank you again for getting me this far, though!
Update! I just figured out I can create a histogram of my data, and then simply use the plot() function to make the curve. I have to figure out my axis units because they were supposed to be from -20cm to +20cm. If you can offer help on that, that would be great. The x-axis runs from 0-300 on here presumably because that is how I "binned" my histogram (hopefully I used that word correctly). I believe I can just use a conversion knowing the actual lengths and the binning, i.e. 0 on this plot refers to -20cm on my initial plot etc..
Now knowing this, how can I use the findpeaks tool on this plot?
The image showed only one peak.
I was considering something like this when I wrote my Answer:
x = linspace(-5, 5); % Independent Variable
y = exp(-(x.^2)); % Gaussian (Prototype)
[pk,loc,w,p] = findpeaks(y); % Get Peaks, Locs, Widths
fpw = loc+[-w w]/2; % FWHM Vector For Plot
figure
plot(x, y)
hold on
plot(x(ceil(fpw)), pk*[1 1]/2, '-r', 'LineWidth',1.5)
hold off
grid
legend('Gaussian', 'FWHM')
I am using the Gaussian to model your non-parametric fit. It should work similar to what I did here.
I have one peak for each energy in my simulation, I'm sorry if I didn't make that clear earlier - I've only shown one peak because I can simply apply what I learn from you to each energy. This looks like it should work, the only question would be for my y values, how do I obtain that from my data? Can I just make a linspace from -20 to +20, then get the y values from my plot in the figure I just made? If so, how would I go about doing that? I am trying the get technique I have seen before, but that doesn't seem to work with what I am doing. Below is the code. Thank you again for helping me with this. Once I can get the proper plot, I will then use your guidence for the FWHM results.
figure(1)
H70 = hist(x70,300); %histogram of my 70MeV protons
HGauss = plot(H70); %plot to make a curve from histogram
x70_values = linspace(-20, 20, 800);
y70_values = get(HGauss, 'Ydata');
plot(x70_values, y70_values) %attempt to make proper plot
I am not certain that I understand the problem.
The findpeaks function will return a peak, location, width (and prominence, if you request it) value for each peak. You would likely have to loop through those to plot them or calculate using them with respect to each peak.
I will try to figure this out. I am sorry I am not conveying my problem unerstandably. I am still new but will use what you have given me to figure out exactly what I am trying to do. I really am very appreciative of your help. I might post another question on here if I cannot figure it out with my research advisor. Thank you again, Star Strider. I am sure this is like trying to explain something to someone who doesn't even understand the language! I appreciate your patience!
No worries!
As always, my pleasure!
I actually tried a method you posted before, but it doesn't quite work the way I want it to. I appreciate any help you can offer!
Best,
Brett
Thank you for bringing it to my attention.
I posted an Answer to it.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by