How do I fit the Gaussian distribution?

54 views (last 30 days)
The noise histogram is a Gaussian distribution as seen in the graph. I want to fit this histogram. I used 'histfit' command but it didn't give correct result. So I wrote code to manually fit it. However, as you can see, this does not give the correct result. How do I fit this histogram correctly? I would be very happy if you could help me with this subject.
noise_filt = cat(2,filt_noise{:});
mu = 0; %mean
noise_sigma = 29*10^-6; %std deviation
noise_varyans = noise_sigma^2;
x = -0.1:0.001:0.1;
pdf = (1/sqrt(2*pi*noise_sigma^2)) .* exp((-(x-mu).^2)/(2*noise_sigma^2));
histogram(noise_filt);
%histfit(noise_filt);
hold on;
plot(x,pdf,'LineWidth',2);
Undefined variable filt_noise.

Accepted Answer

Star Strider
Star Strider on 14 Sep 2021
It gave a much better result when I ran it (R2021a) —
LD = load('noise_filt.mat');
noise_filt = LD.noise_filt;
figure
hhf = histfit(noise_filt)
df = fitdist(noise_filt(:), 'Normal')
df =
NormalDistribution
Normal distribution
mu = 3.27713e-05 [9.07426e-06, 5.64683e-05]
sigma = 0.00865728 [0.00864056, 0.00867407]
It won’t be exact unless it has a ‘perfect’ normal distribution. That’s likely as good as it gets.
.
  8 Comments
studentmatlaber
studentmatlaber on 22 Sep 2021
I manually fit in the weibull distribution. I didn't use the histfit command. That's why I couldn't find a solution in the mse account. If you know any other way, please tell me, I'm so desperate. I created a question for Gaussian. https://uk.mathworks.com/matlabcentral/answers/1458414-how-to-calculate-mse-for-gaussian-histogram
Star Strider
Star Strider on 22 Sep 2021
The histfit function should work with the Weibull distribution, and wblfit should work to estimate the parameters and confidence intervals on them. Getting the ‘typical’ statistics that relate to a nonlinear fit with respect to a histogram and a specific distribution may not be the correct approach.
The distribution fitting functions (using the maximum likelihood estimate) fit the parameters of the distribution, not the histogram. Ths histogram is simply provided in order to understand the nature of the fitted distribution and how it relates to the data. The mlecov function can provide a covariance matrix on the parameters.
I’m sort of lost here. I thought we already solved this problem with the nonlinear fit to the histogram.
.

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!