Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/collect.absolute.energy.R
finds the max value of a spectrum, then spreads out from that peak until it has determined a region whose area meets a fixed sum. Given the same sum, a low peak will yield a broader region than a high one.
1 | collect.absolute.energy(spk, desired.sum)
|
spk |
a vector that corresponds to a peak trace. |
desired.sum |
the area under the curve that you are looking for |
this function assumes all of spk >= 0, and will perform oddly if any values are negative.
a vector with three entries:
lo |
the index of the beginning of the region (inclusive) |
hi |
the index of the end of the region (inclusive) |
total |
the sum of the heights within the region |
Benjamin N. Taft ben.taft@landmarkacoustics.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (spk, desired.sum)
{
total <- max(spk)
N <- length(spk)
lo <- hi <- match(total, spk)[1]
while (total < desired.sum) {
action.case <- switch(1 + 2 * (is.na(lo) || lo < 2 ||
spk[lo - 1] < 0) + (is.na(hi) || is.na(spk[hi + 1]) ||
spk[hi + 1] < 0), ifelse(spk[lo - 1] < spk[hi + 1],
1, 2), 1, 2, 3)
if (action.case == 1) {
lo <- lo - 1
total <- total + spk[lo]
}
else if (action.case == 2) {
hi <- hi + 1
total <- total + spk[hi]
}
else {
break
}
}
if (is.na(lo) || lo < 1)
lo <- 1
if (is.na(hi) || hi > N)
hi <- N
return(c(lo, hi, total))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.