R/computes_peak_width_ppm.R

Defines functions computes_peak_width_ppm

Documented in computes_peak_width_ppm

#' Peak width estimation for integration
#'
#' Estimates the peak width (ppm width) to perform peak integration using
#' `nmr_integrate_peak_positions`. for this purpose, the full width at half maximum
#' of a peak from alanine doublet is considered.
#'
#' @family peak integration functions
#' @family nmr_dataset_1D functions
#' @param nmr_dataset An [nmr_dataset_1D].
#' @return Numerical. A peak width (ppm) that may be set in `nmr_integrate_peak_positions`

computes_peak_width_ppm = function(nmr_dataset) {
    ppms = nmr_dataset$axis
    alanine = which((nmr_dataset$axis > 1.485) &
                                        (nmr_dataset$axis < 1.515))
    alanine_vector = ppms[alanine]
    
    x = alanine_vector
    y = nmr_dataset$data_1r[1, alanine]
    d = data.frame(x, y)
    #plot(d, type="l", xlab = "Alanine", ylab = "a.u.")
    xmax <- d$x[d$y == max(d$y)]
    
    #x1 <- d$x[d$x < xmax][which.min(abs(d$y[d$x < xmax]-max(d$y)/2))]
    x2 <- d$x[d$x > xmax][which.min(abs(d$y[d$x > xmax] - max(d$y) / 2))]
    x3 <- abs((x2 - xmax) * 2)
    x4 <- x2 - x3
    
    #points(c(x2, x4), c(d$y[d$x==x2], d$y[d$x==x4]), col="red")
    FWHM <- x3
    message("calculated width for integration is ", FWHM, " ppm")
    return(FWHM)
}

Try the AlpsNMR package in your browser

Any scripts or data that you put into this service are public.

AlpsNMR documentation built on April 1, 2021, 6:02 p.m.