Nothing
#' NLS
#' @description Non-linear shrinkage
#' @details This function is used to process phase error correction through non-linear shrinkage, followed by Polynomial baseline correction when necessary.
#' @param specdat A complex number vector of observed frequency domain data.
#' @param withBC A logical parameter that enables/disables baseline correction after baseline correction
#' @return A numeric vector of phase corrected absorption spectrum
#' @concept phase correction
#' @author Aixiang Jiang
#' @references
#'
#' Liland KH, Almøy T, Mevik B (2010), Optimal Choice of Baseline Correction for Multivariate Calibration of Spectra, Applied Spectroscopy 64, pp. 1007-1016.
#' @examples
#' data("fdat")
#' nls_phased1 <- NLS(fdat$frequency_domain)
#' @export
NLS = function(specdat, withBC = TRUE){
cplxDat=specdat
pp=(Re(cplxDat))**2+(Im(cplxDat))**2
mm=sqrt(pp)
peakIndex=peakSearch(mm)
k=length(peakIndex)
peak1=peakIndex[-k]
peak2=peakIndex[-1]
peaks=cbind(peak1,peak2)
#### find valley index
valleyIndex=apply(peaks,1,FUN=function(x){
mdat=mm[x[1]:x[2]]
which.min(mdat)+x[1]-1
})
nn=length(specdat)
valleyIndex=c(1,valleyIndex, nn)
vv=length(valleyIndex)
valleyL=valleyIndex[1:(vv-1)]
valleyL[2:(vv-1)]=valleyL[2:(vv-1)]+1
valleyR=valleyIndex[2:vv]
valleys=cbind(valleyL,valleyR)
phasedComb=apply(valleys,1,FUN=function(x){
pdat=pp[x[1]:x[2]]
mdat=mm[x[1]:x[2]]
return(pdat*max(mdat)/max(pdat))
})
phasedAll=unlist(phasedComb)
if(withBC == TRUE){
tryBL=myBaseline(phasedAll,bsDf=5, BL_method="modpolyfit")
phasedAll = as.numeric(tryBL)
}
return(phasedAll)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.