||
%%%%% 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$')
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-10-20 01:39
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社