Fit Normalised Gaussian to data

조회 수: 5 (최근 30일)
Dana Shoukroun
Dana Shoukroun 2021년 4월 27일
편집: Matt J 2021년 4월 28일
Hi,
I am trying to fit a nromalised Gaussian to my data, using
f(x) = a/sqrt(2pi*sigma^2) * exp (-(x-mu)^2/sigma^2)
However the fit function in matla does not accound for the sigma coefficient. Is there a way to modify the equation of the fit function? I tried to do a manual fit but it doesn't seem to work.
Thanks
  댓글 수: 2
Alex Sha
Alex Sha 2021년 4월 28일
Hi, post out your data please.
Matt J
Matt J 2021년 4월 28일
I am trying to fit a nromalised Gaussian to my data, using
Shouldn't it be,
f(x) = a/sqrt(2pi*sigma^2) * exp (-0.5*(x-mu)^2/sigma^2)

댓글을 달려면 로그인하십시오.

답변 (1개)

Matt J
Matt J 2021년 4월 28일
편집: Matt J 2021년 4월 28일
You can use,
Example:
%% Synthetic data
fn=@(x,a,mu,sigma) a./sqrt(2*pi*sigma^2) .* exp (-(x(:)-mu).^2/2/sigma^2);
xdata=linspace(-3,9,20).';
ydata=fn(xdata,1,3,2)+0.006*randn(size(xdata));
%% Do the fit
ulb={0,[],[],[]};
[params,resnorm, residual,exitflag,output]=gaussfitn(xdata,ydata,[],ulb,ulb);
Local minimum possible. lsqcurvefit stopped because the final change in the sum of squares relative to its initial value is less than the value of the function tolerance.
[A,mu,variance]=deal(params{2:4});
sigma=sqrt(variance);
a=A*sqrt(2*pi*variance);
%% Verify
xs=linspace(min(xdata),max(xdata),1000);
plot(xdata,ydata,'o',xs, fn(xs,a,mu,sigma));shg

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by