Professional Documents
Culture Documents
MatlabinChemicalEngineeringatCMU
MatlabinChemicalEngineering
atCMU
Home
Blog
Archives
+cmu-Matlabpackage
Categories
Tutorials
Contents
curve fitting to get overlapping peak areas
read in the data file
first we get the number of data points, and read up to the data
initialize the data vectors
LatestPosts
Last post for a while
what_do_you_want.m
Peak finding in Raman spectroscopy
curve fitting to get overlapping peak
areas
Colors, 3D Plotting, and Data
Manipulation
first we get the number of data points, and read up to the data
i=0;
while1
line=fgetl(fid);
sm=strmatch('#ofPoints',line);
if~isempty(sm)
regex='#ofPoints(.*)';
[matchtokens]=regexp(line,regex,'match','tokens');
npoints=str2num(tokens{1}{1});
elseifstrcmp(line,'R.Time Intensity')
break
i=i+1
end
end
http://matlab.cheme.cmu.edu/2012/06/22/curvefittingtogetoverlappingpeakareas/
1/6
23/01/2015
MatlabinChemicalEngineeringatCMU
http://matlab.cheme.cmu.edu/2012/06/22/curvefittingtogetoverlappingpeakareas/
2/6
23/01/2015
MatlabinChemicalEngineeringatCMU
http://matlab.cheme.cmu.edu/2012/06/22/curvefittingtogetoverlappingpeakareas/
3/6
23/01/2015
MatlabinChemicalEngineeringatCMU
nonlinear fitting
now we use nonlinear fitting to get the parameters that best fit our data, and plot the fit
on the graph.
pars=nlinfit(t,intensity,@two_peaks,parguess)
plot(t,two_peaks(pars,t),'r')
legend'rawdata''initialguess''totalfit'
pars=
1.0e+03*
1.30520.00490.00010.00005.31620.00510.00000.0001
the fits are not perfect. The small peak is pretty good, but there is an unphysical tail on
the larger peak, and a small mismatch at the peak. There is not much to do about that, it
means the model peak we are using is not a good model for the peak. We will still
integrate the areas though.
now extract out the two peaks and integrate the areas
pars1=pars(1:4)
pars2=pars(5:8)
http://matlab.cheme.cmu.edu/2012/06/22/curvefittingtogetoverlappingpeakareas/
4/6
23/01/2015
MatlabinChemicalEngineeringatCMU
peak1=asym_peak(pars1,t);
peak2=asym_peak(pars2,t);
plot(t,peak1)
plot(t,peak2)
legend'rawdata''initialguess''totalfit''peak1''peak2';
area1=trapz(t,peak1)
area2=trapz(t,peak2)
pars1=
1.0e+03*
1.30520.00490.00010.0000
pars2=
1.0e+03*
5.31620.00510.00000.0001
area1=
1.3052e+03
area2=
5.3162e+03
This sample was air, and the first peak is oxygen, and the second peak is nitrogen. we
http://matlab.cheme.cmu.edu/2012/06/22/curvefittingtogetoverlappingpeakareas/
5/6
23/01/2015
MatlabinChemicalEngineeringatCMU
come pretty close to the actual composition of air, although it is low on the oxygen
content. To do better, one would have to use a calibration curve.
end
%categories:dataanalysis
%post_id=1994;%deletethislinetoforcenewpost;
%permaLink=http://matlab.cheme.cmu.edu/2012/06/22/curvefittingtoget
overlappingpeakareas/;
Published with MATLAB 7.12
0Comments
matlab
Login
Share Favorite
SortbyBest
Startthediscussion
Bethefirsttocomment.
Subscribe
AddDisqustoyoursite
Privacy
http://matlab.cheme.cmu.edu/2012/06/22/curvefittingtogetoverlappingpeakareas/
6/6