chau8970的个人博客分享 http://blog.sciencenet.cn/u/chau8970

博文

Matlab 高斯拟合多个峰

已有 4941 次阅读 2021-5-15 18:00 |个人分类:Matlab codes|系统分类:科研笔记


image.png


%%%%% The code is developed to fit overlap peaks with the gaussian function. 

%%%%% Here we fit four peaks. It can be easily extended to any number of peaks.

%%%%% Date: 15/May/2021

 

clear

clc

close all

 

set(gcf,'unit','centimeters','Position',[59 1  20  10]); % set figure size and position

set (0,'defaultlineLinewidth',2); % default line width

set(0,'defaultTextInterpreter','latex');  % set default interpreter, use $ $ to indicate latex form

 

%%%%%%%%% fitting function

gaussEqn = 'a1*exp(-((x-b1)/c1)^2)+a2*exp(-((x-b2)/c2)^2)+a3*exp(-((x-b3)/c3)^2)+a4*exp(-((x-b4)/c4)^2)+a5*exp(-((x-b5)/c5)^2)+d';

 

 

x=850:2:1200;

x=x';

 

%%%%%%%%% generate data

y=100*exp(-(x-950).^2/260)+200*exp(-(x-1000).^2/200)+...

    120*exp(-(x-1041).^2/220)+70*exp(-(x-1082).^2/280)+...

    20*exp(-(x-1120).^2/300) ;

 

%%%%% give start points

%%%%%%        [a1  a2 a3  a4 a5  b1  b2 b3  b4 b5 c1  c2 c3  c4 c5 d]

startPoints = [1   1  0.5 0.1 0.2 950 1000 1040 1080 1120 2  2 2 1 1 0.6];

 

hold on 

 

%%%% fitting the data with four peaks gaussian function

f1 = fit(x,y,gaussEqn,'Start', startPoints)

plot(x,y,'o') % plot the data

 

plot(f1) % plot the fitting function

 

box on

set(gca,'FontSize',18,'LineWidth',1);

legend('data','Gaussian function')

 

xlabel('$x$')

ylabel('$y$')




https://wap.sciencenet.cn/blog-3474482-1286694.html

上一篇:Matlab 自定义颜色表 colormap
收藏 IP: 218.212.57.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

全部作者的其他最新博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-27 13:17

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部