Description Usage Arguments Details Value Author(s) See Also Examples
View source: R/collect.energy.R
goes to the max of the input vector, then walks out in either direction until the user-specified amplitude sum is achieved
1 | collect.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
spectrum
collect.absolute.energy
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 | ##---- 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)
{
ends <- rep(match(max(spk), spk), 2)
N <- length(spk)
total <- 0
current.step <- 1
while (total < desired.sum) {
temp.next <- c(ifelse(ends[1] > 1, spk[ends[1] - 1],
-Inf), ifelse(ends[2] < N, spk[ends[2] + 1], -Inf))
now <- 1 + (temp.next[1] < temp.next[2])
if (is.infinite(temp.next[now]))
break
height <- spk[ends[now]] - temp.next[now]
width <- ifelse(height > 0, current.step, 1)
ends[now] <- ends[now] + ifelse(now == 1, -1, 1)
total <- total + width * height
current.step <- current.step + 1
}
return(c(ends, total))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.