# collect.energy: finds a region the under the highest point in a 1-D landscape... In landmarkacoustics/SoundPoints-R: an R version of the SoundPoints algorithm

## Description

goes to the max of the input vector, then walks out in either direction until the user-specified amplitude sum is achieved

## Usage

 `1` ```collect.energy(spk, desired.sum) ```

## Arguments

 `spk` a vector that corresponds to a peak trace. `desired.sum` the area under the curve that you are looking for

## Details

this function assumes all of spk >= 0, and will perform oddly if any values are negative.

## Value

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

## Author(s)

Benjamin N. Taft [email protected]

## See Also

`spectrum` `collect.absolute.energy`

## Examples

 ``` 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, spk[ends - 1], -Inf), ifelse(ends < N, spk[ends + 1], -Inf)) now <- 1 + (temp.next < temp.next) 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)) } ```

landmarkacoustics/SoundPoints-R documentation built on Sept. 26, 2018, 9:08 a.m.