V March 4 2015 Contents 1 Introduction 2 Polynomial Baselines 21 Syntax parameters 2 22 General Use 2 23 Fitting polynomial baselines using least squares ID: 60313
Download Pdf The PPT/PDF document "Fitting Baselines to Spectra Claudia Bel..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
FittingBaselinestoSpectraClaudiaBeleites Claudia.Beleites@chemometrix.gmbh-34.;妉 DIARamanSpectroscopyGroup,UniversityofTrieste/Italy(2005{2008)SpectroscopyImaging,IPHT,Jena/Germany(2008{2017)OPV,JKI,Berlin/Germany(2017{2019)ArbeitskreisLebensmittelmikrobiologieundBiotechnologie,HamburgUniversity,Hamburg/GermanChemometricConsultingandChemometrixGmbH,Wolfersheim/Germany(since2016)May27,2020Contents 1Introduction 1 2PolynomialBaselines 1 2.1Syntax¶meters .......................................2 2.2GeneralUse .............................................2 2.3Fittingpolynomialbaselinesusingleastsquares .......................2 2.4Themechanismofautomaticallyttingthebaselineinspc.t.poly.below ........3 2.5Specifyingthespectralrange ...................................4 2.6Fittingpolynomialsofdierentorders .............................5 2.7Thenoiselevel ...........................................5 3RubberbandMethod 1IntroductionThisdocumentdiscussesbaselinecorrectionmethodsthatcanbeusedwithhyperSpec.hyperSpecprovidestwottingfunctionsforpolynomialbaselines,spc.fit.polyandspc.fit.poly.below.Anotherpossibilityisspc.rubberband,a\rubberband"methodthatdeterminessupportpointsbyndingtheconvexhullofeachspectrum.Thebaselinesarethenpiecewiselinearor(smoothing)splinesthroughthesupportpoints.Pleasenotethataspecializedpackageforbaselinetting,baseline[ 1 ],existsthatprovidesmanymoremethodstotbaselinestospectroscopicdata.UsingbaselinewithhyperSpecobjectsisdemonstratedinvignette("hyperspec").2PolynomialBaselinesIncontrasttomanyotherprogramsthatprovidebaselinecorrectionmethods,hyperSpec'spolynomialbaselinefunctionsdoleastsquarests.However,thebaselinescanbeforcedthroughparticular points,ifthisbehaviourisneeded.Themaindierencebetweenthetwofunctionsisthatspc.fit.polyreturnsaleastsquarestthroughthecompletespectrumthatisgivenint.towhereasspc.fit.poly.belowtriestondappropriatespectralregionstotthebaselineto.2.1Syntax¶metersspc.fit.poly(fit.to,apply.to=fit.to,poly.order=1spc.fit.poly.below(fit.to,apply.to=fit.to,poly.order=1,npts.min=NULL,noise=0)fit.to:hyperSpecobjectwiththespectrawhosebaselinesaretobetted.apply.to:hyperSpecobjectgivingthespectralrange,onwhichthebaselinesshouldbeeval-uated.IfapplyisNULL,ahyperSpecobjectwiththepolynomialcoecientsisreturnedinsteadofevaluatedbaselines.poly.order:polynomialorderofthebaselinesnpts.min:minimalnumberofdatapointsperspectrumtobeusedforthet.npts.mindefaultstothelargerof3times(poly.order+1)or thofthenumberofdatapointsperspectrum.Ifnpts.minpoly.order,awarningisissuedandnpts.min-poly.order+1isused.noise:avectorgivingtheamountofnoise,seebelow.2.2GeneralUseBothfunctionstthepolynomialtothespectralrangegiveninhyperSpecobjectt.to.Ifapply.toisnotNULL,thepolynomialsareevaluatedonthespectralrangeofapply.to.Otherwise,thepolynomialcoecientsarereturned.Subtractingthebaselineisuptotheuser,itiseasilydoneashyperSpecprovidesthe(minus)operator.2.3FittingpolynomialbaselinesusingleastsquaresCommonly,baselinesaretusing(single)supportpointsthatarespeciedbytheuser.Also,usuallysupportpointisusedforapolynomialoforder.Thisapproachisappropriateforspectrawithhighsignaltonoiseratio.Suchabaselinecanbeobtainedbyrestrictingthespectraint.tototherespectivepoints(seegure 1 ):bl-spc.fit.poly(chondro[c(1,101),,c(633,1788)],chondro[c(1,101)]).99;冘plot(chondro[c(1,101)],plot.args=list(ylim=c(200,600)),col=1:2).99;冘plot(chondro[c(1,101),,c(633,1788)],add=TRUE,col=1:2,+lines.args=list(type="p",pch=20)).99;冘plot(bl,add=TRUE,col=1:2) 600700800900100011001200130014001500160017001800 200300400500600Dn cm-1I / a.u. Figure1Fittingalinearbaselinethroughtwopoints.Ifthesignaltonoiseratioisnotideal,wavelengthsthatworkneforonespectrum(black)maynotbeappropriateforanother(red).However,ifthesignaltonoiseratioisnotideal,apolynomialwithsupportingpoints(i.e.withzerodegreesoffreedom)issubjecttoaconsiderableamountofnoise.Ifontheotherhand,moredatapointsconsistingofbaselineonlyareavailable,theuncertaintyonthepolynomialcanbereducedbyaleastsquarest.Bothspc.fit.polyandspc.fit.poly.belowthereforeprovideleastsquaresttingforthepoly-nomial.spc.fit.polytstothewholespectralregionoft.to.Thus,forbaselinettingthespectraneedtobecuttoappropriatewavelengthrangesthatdonotcontainanysignal.Inordertospeedupcalculations,theleastsquarestisdonebyusingtheVandermondematrixandsolvingtheequationsystembyqr.solve.Thistisnotweighted.Aspectralregionwithmanydatapointsthereforehasgreaterin\ruenceontheresultingbaselinethanaregionwithjustafewdatapoints.Itisuptotheusertodecidewhetherthisshouldbecorrectedforbyselectingappropriatenumbersofdatapoints(e.g.byusingreplicatesoftheshorterspectralregion).2.4Themechanismofautomaticallyttingthebaselineinspc.fit.poly.belowspc.fit.poly.belowtriestoautomaticallyndappropriatespectralregionsforbaselinetting.Thisisdonebyexcludingspectralregionsthatcontainsignalsfromthebaselinetting.Theideaisthatalldatapointsthatlieaboveattedpolynomial(initiallythroughthewholespectrum,thenthroughtheremainingpartsofthespectrum)willbetreatedassignalandthusbeexcludedfromthebaselinetting.Thesupportingpointsforthebaselinepolynomialsarecalculatediteratively:1.Apolynomialoftherequestedorderisttotheconsideredspectralrange,initiallytothewholespectrumgivenint.to 600700800900100011001200130014001500160017001800 50010001500Dn cm-1I / a.u.spectrum 1 Figure2Iterativettingofthebaseline.Thedotsgivethesupportingpointsforthenextiteration'sbaseline,color:iterations. 17001705171017151720172517301735174017451750 200300400500Dn cm-1I / a.u. Figure3In\ruenceoffit.toonthebaselinepolynomial.Theblackbaselineisttothespectralrange17001750cm,theblueto17201750cmonly.2.Onlythepartsofthespectrumthatliebelowthispolynomialplusthenoiseareretainedassupportingpointsforthenextiteration.Thesetwostepsarerepeateduntileithernofurtherpointsareexcluded,orthenextpolynomialwouldhavelessthannpts.minsupportingpoints.Thebaselinesandrespectivesupportingpointsforeachiterationofspc.fit.poly.below(chondro[1],poly.order=1)areshowningure 2 .2.5SpecifyingthespectralrangeItispossibletoexcludespectralregionsthatdonotcontributetothebaselinefromthetting,whilethebaselineisusedforthewholespectrum.Thisselectionofappropriatespectralregionsisessentialforspc.fit.poly.Butalsospc.fit.poly.belowcanbenetfromnarrowerspectralranges:thettinggainsspeed.Thedefaultvaluefornpts.mindependsonthenumberofdatapointsperspectrum.Thusoneshouldalsoconsiderrequiringmoresupportpointsthanthedefaultvaluesuggests. 60080010001200140016001800 50010001500Dn cm-1I / a.u.spectrum 1 60080010001200140016001800 50010001500Dn cm-1I / a.u.spectrum 1 60080010001200140016001800 50010001500Dn cm-1I / a.u.spectrum 1 Figure4Baselinepolynomialttotherstspectrumofthechondrodatasetoforder0{2(lefttoright).Thedotsindicatethepointsusedforthettingofthepolynomial.system.time(spc.fit.poly.below(chondro,NULL,npts.min=20))usersystemelapsed0.3550.0230.378system.time(spc.fit.poly.below(chondro[,,c(min~700,1700~max)],NULL,npts.min=20))usersystemelapsed0.1910.0000.190Thechoiceofthespectralrangeinfit.toin\ruencestheresultingbaselinestoacertainextent,asbecomesclearfromgure 3 .2.6FittingpolynomialsofdierentordersFigure 4 showstheresultingbaselinepolynomialofspc.fit.poly.below(chondro[1],poly.order=order)withorder0to3fortherstspectrumofthechondrodataset.2.7ThenoiselevelBesidesdeningaminimalnumberofsupportingpoints,a\noiselevel"maybegiven.Consideraspectralrangeconsistingonlyofnoise.Theupperpartofgure 5 illustratestheproblem.Asthebaselinettingalgorithmcannotdistinguishbetweennoiseandrealbandsappearingabovethettedpolynomial,theresultingbaseline(black)istoolowifthenoiseparameterisnotgiven.Settingthenoiselevelto4(2standarddeviations),thettingconvergesimmediatelywithamuchbetterresult.Theresultingbaselinesforspc.fit.poly.below(chondro[1],poly.order=1,noise=12)ofthewholespectrumareshowninthemiddleandlowerpartofgure 5 noisemaybeasinglevalueforallspectra,oravectorwiththenoiselevelforeachofthespectraseparately.3RubberbandMethodParticularlyRamanspectraoftenshowincreasingbackgroundtowards.Inthiscase,polyno-mialbaselinesofteneitherneedhighorderorresidualbackgroundisleftinthespectra.Inthatcase,smoothingsplinesttedthroughthesupportingpointsareagoodalternative.Fortheparacetamolspectrum(g. 6 ),anoiselevelof300countsandtheequivalentof20degreesoffreedomworkwell. 0102030405060708090100 9698100102104 600700800900100011001200130014001500160017001800 50010001500Dn cm-1I / a.u.spectrum 1 Figure5Iterativettingofthebaselinewithnoiselevel.Upperpart:eectsofthenoiseparameteronthebaselineofaspectrumconsistingonlyofnoiseandoset:withoutgivingnoisetheresultingbaseline(black)isclearlytoolow.Anoiselevelof4resultsinthebluebaseline.Thelowerpartshowthebaselinettingwithnoiselevelonthecompletespectrum.Colour:iterations,dots:supportingpointsfortherespectivelynextbaseline.Dashed:baselineplusnoise.Allpointsabovethislineareexcludedfromthenextiteration.bl-spc.rubberband(paracetamol[,,175~1800],noise=300,df=20)However,thereispossiblysomebackgroundleftbetween1200and1750cm-1wheretheoriginalspectrumisslightlyconcave.Thiscanbecorrectedbybendingthespectrumbeforeapplyingtherubberbandcorrection(g. 7 ):bend-5e4*wl.eval(paracetamol[,,175~1800],function(x)x^2,normalize.wl=normalize01).99;冘bl-spc.rubberband(paracetamol[,,175~1800]+bend)-bendReferences[1]KristianHovdeLiland,TrygveAlmy,andBjrn-HelgeMevik.Optimalchoiceofbaselinecor-rectionformultivariatecalibrationofspectra.AppliedSpectroscopy,64:1007{1016,2010.SessionInfoRversion3.6.3(2020-02-29)Platform:x86_64-pc-linux-gnu(64-bit)Runningunder:Ubuntu18.04.4LTSMatrixproducts:defaultBLAS:/usr/lib/x86_64-linux-gnu/openblas/libblas.so.3LAPACK:/usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so 20040060080010001200140016001800 1000020000300004000050000Dn cm-1I / a.u. (a)paracetamolwiththerubberbandttedbaseline. 20040060080010001200140016001800 010000200003000040000Dn cm-1I / a.u. (b)Correctedspectrum.Figure6Rubberbandbaselinesfortheparacetamolspectrum. 20040060080010001200140016001800 10000300005000070000Dn cm-1I / a.u. (a)Bentparacetamolspectrumandrubberbandbaseline. 20040060080010001200140016001800 010000200003000040000Dn cm-1I / a.u. (b)Correctedspectrum.Figure7Rubberbandbaselinesfortheparacetamolspectrumafterbending.locale:[1]LC_CTYPE=de_DE.UTF-8LC_NUMERIC=CLC_TIME=de_DE.UTF-8[4]LC_COLLATE=CLC_MONETARY=de_DE.UTF-8LC_MESSAGES=de_DE.UTF-8[7]LC_PAPER=de_DE.UTF-8LC_NAME=CLC_ADDRESS=C[10]LC_TELEPHONE=CLC_MEASUREMENT=de_DE.UTF-8LC_IDENTIFICATION=Cattachedbasepackages:[1]gridstatsgraphicsgrDevicesutilsdatasetsmethodsbaseotherattachedpackages:[1]hyperSpec_0.99-20200527xml2_1.3.2ggplot2_3.3.0lattice_0.20-41loadedviaanamespace(andnotattached):[1]Rcpp_1.0.4.6magrittr_1.5tidyselect_1.0.0munsell_0.5.0[5]colorspace_1.4-1R.cache_0.14.0R6_2.4.1jpeg_0.1-8.1[9]rlang_0.4.6dplyr_0.8.5tools_3.6.3gtable_0.3.0[13]png_0.1-7R.oo_1.23.0latticeExtra_0.6-29withr_2.2.0[17]ellipsis_0.3.0lazyeval_0.2.2digest_0.6.25assertthat_0.2.1[21]tibble_3.0.1lifecycle_0.2.0crayon_1.3.4R.rsp_0.43.2[25]RColorBrewer_1.1-2purrr_0.3.4vctrs_0.2.4R.utils_2.9.2[29]testthat_2.3.2glue_1.4.0compiler_3.6.3pillar_1.4.4[33]scales_1.1.0R.methodsS3_1.8.0pkgconfig_2.0.3