matlab fit option,Create or modify fit options object

Create a Gaussian fit, inspect the confidence intervals, and specify lower bound fit options to help the algorithm.

Create a noisy sum of two Gaussian peaks, one with a small width, and one with a large width.

a1 = 1; b1 = -1; c1 = 0.05;

a2 = 1; b2 = 1; c2 = 50;

x = (-10:0.02:10)';

gdata = a1*exp(-((x-b1)/c1).^2) + ...

a2*exp(-((x-b2)/c2).^2) + ...

0.1*(rand(size(x))-.5);

plot(x,gdata)

6cb30810f86e32ab2710027ac98da2fb.png

Fit the data using the two-term Gaussian library model.

gfit = fit(x,gdata,'gauss2')

gfit =

General model Gauss2:

gfit(x) = a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2)

Coefficients (with 95% confidence bounds):

a1 = -0.145 (-1.486, 1.195)

b1 = 9.725 (-14.71, 34.16)

c1 = 7.117 (-15.84, 30.07)

a2 = 14.06 (-1.957e+04, 1.96e+04)

b2 = 607 (-3.193e+05, 3.205e+05)

c2 = 375.9 (-9.737e+04, 9.812e+04)

plot(gfit,x,gdata)

35930206cae03dedd62820aac1d4f10a.png

The algorithm is having difficulty, as indicated by the wide confidence intervals for several coefficients.

To help the algorithm, specify lower bounds for the nonnegative amplitudes a1 and a2 and widths c1, c2.

options = fitoptions('gauss2', 'Lower', [0 -Inf 0 0 -Inf 0]);

Alternatively, you can set properties of the fit options using the form options.Property = NewPropertyValue.

options = fitoptions('gauss2');

options.Lower = [0 -Inf 0 0 -Inf 0];

Recompute the fit using the bound constraints on the coefficients.

gfit = fit(x,gdata,'gauss2',options)

gfit =

General model Gauss2:

gfit(x) = a1*exp(-((x-b1)/c1)^2) + a2*exp(-((x-b2)/c2)^2)

Coefficients (with 95% confidence bounds):

a1 = 1.005 (0.966, 1.044)

b1 = -1 (-1.002, -0.9988)

c1 = 0.0491 (0.0469, 0.0513)

a2 = 0.9985 (0.9958, 1.001)

b2 = 0.8059 (0.3879, 1.224)

c2 = 50.6 (46.68, 54.52)

plot(gfit,x,gdata)

aba077739d909da35be9d4f3410f1e2b.png

This is a much better fit. You can further improve the fit by assigning reasonable values to other properties in the fit options object.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值