Fitting data to Gaussian function forced to have zero mean

5 ビュー (過去 30 日間)
matnewbie
matnewbie 2018 年 7 月 11 日
コメント済み: matnewbie 2018 年 7 月 12 日
I am trying to fit experimental data to a Gaussian function forced to have zero mean. I tried to use the explicit expression for the Gaussian and nlinfit, but the sigmoidal shape of the Gaussian disappears (it behaves like an exponential decay function). I also tried to use fit with the 'gauss1' option, but I don't know how to set a zero value for the mean and the Gaussian distribution I obtain has the mean where it fits better the data (therefore shifted with respect to zero). What is the best approach to obtain what I need?

回答 (1 件)

dpb
dpb 2018 年 7 月 11 日
Use mle; there are some examples in the doc fitting distributions with fixed parameters...
Given x is your observation vector, and under the assumption the offset is relatively small in comparison to the variance,
[phat,pci] = mle(x,'pdf',@(x,sigma) pdf('normal',x,0,sigma),'start',std(x));
should give reasonable estimates.
  1 件のコメント
matnewbie
matnewbie 2018 年 7 月 12 日
Thank you, but I solved in another way, since I had x,y data to fit... I used this code snippet:
meanval=sum(x.*y)/sum(y);
sigma0=sqrt(sum(y.*(x-meanval).^2)/sum(y));
CenteredGaussian=@(b,x)(b(1)*exp(-x.^2/(2*b(2)^2)));
sol=nlinfit(x,y,CenteredGaussian,[max(y) sigma0]);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by