Full width at half maximum
Compute peak full-width at half maximum or at another level of peak maximum for a vector or matrix.
fwhm( x = seq_len(length(y)), y, ref = c("max", "zero", "middle", "min", "absolute"), level = 0.5 )
x
: samples at which y
is measured, specified as a vector. I.e., y
is sampled as y[x]
. Default: seq_len(length(y))
.
y
: signal to find the width of. If y
is a matrix, widths of all columns are computed.
ref
: reference. Compute the width with reference to:
"max" | "zero"
: max(y)
"middle" | "min"
: min(y) + max(y)
"absolute"
: an absolute level of y
level
: the level at which to compute the width. Default: 0.5.
Full width at half maximum, returned as a vector with a length equal to the number of columns in y
, or 1 in case of a vector.
x <- seq(-pi, pi, 0.001) y <- cos(x) w <- fwhm(x, y) m <- x[which.max(y)] f <- m - w/2 t <- m + w/2 plot(x, y, type="l", panel.first = { usr <- par('usr') rect(f, usr[3], t, usr[4], col = rgb(0, 1, 0, 0.4), border = NA) }) abline(h = max(y) / 2, lty = 2, col = "gray")
Petr Mikulik.
Conversion to R by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com .