How do I fit a PDF to a histogram?
10 views (last 30 days)
Show older comments
I have a histogram that I need to fit a PDF to. The issue is that I only have the frequency information, I don't have the data the histogram was generated from. This is because it was generated pixel by pixel from a large image and then thresholded with an algorithm. I want to find the equation for the PDF that fits the histogram the best. All of the resources I've found online seem to require the actual data set as well, and not just the frequency information. Does anyone know if this is possible? I also have an empirical PDF generated by normalizing the histogram frequencies. Is there a way I could fit a Gaussian equation to that? Thanks.
0 Comments
Answers (1)
Are Mjaavatten
on 24 Oct 2017
If you have access to the curve fitting toolbox (I don't) you can probably use fit. If not, the following example illustrates how to make a fair approximation:
y = randn(10000,1)+7;
x = 3:0.1:11;
binsize = diff(x(1:2));
n = hist(y,x);
f = n/sum(n)/binsize; % probalility per unit length
f = max(f,100*eps); % Force cf to be monotonic
cf = cumsum(f)*binsize; % Cumulative distribution function
mu = interp1(cf,x,0.5);
sigma = diff(interp1(cf,x,...
[0.5*(1+erf(-1/sqrt(2))),0.5*(1+erf(1/sqrt(2)))]))/2;
plot(x,f,x,exp(-(x-mu).^2/2/sigma^2)/sigma/sqrt(2*pi));
0 Comments
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!