make.peaks: Extract a continuous peak-frequency contour from a...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/make.peaks.R

Description

At each time step of a spectrogram, this function finds the maximum-energy frequency, then identifies the band around that peak that holds a predetermined total amount of energy

Usage

1
make.peaks(spg, passband, amplitude.cutoff)

Arguments

spg

a spectrogram object

passband

a two-element vector that defines the frequency range that will be searched

amplitude.cutoff

a single numeric value that defines the total area of each peak

Value

a data frame in which each row corresponds to a time point of the input spectrogram. It has the following columns:

time

the time that the row describes

min.frequency

the lowest frequency in the peak (inclusive)

max.frequency

the highest frequency in the peak (inclusive)

amplitude.sum

the total of all the amplitudes in the peak's range

mean.frequency

the weighted mean frequency of the peak

mean.amplitude

the mean amplitude of the peak

max.amplitude

the peak's greatest amplitude

amplitude.range

the difference between the peak's maximum amplitude and its minimum amplitude

Author(s)

Benjamin N. Taft ben.taft@landmarkacoustics.com

See Also

spectrogram

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
26
27
28
##---- 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 (spg, passband, amplitude.cutoff) 
{
    freqs <- attr(spg, "frequency")
    g <- freqs > min(passband)
    below <- sum(!g)
    g <- g & freqs < max(passband)
    peak.values <- data.frame(t(apply(spg[, g], 1, collect.energy, 
        amplitude.cutoff)))
    names(peak.values) <- c("lo", "hi", "sum")
    peak.values[, 1:2] <- peak.values[, 1:2] + below
    peaks <- data.frame(time = attr(spg, "time"), min.frequency = freqs[peak.values$lo], 
        max.frequency = freqs[peak.values$hi], amplitude.sum = peak.values$sum)
    for (i in 1:nrow(peaks)) {
        ix <- peak.values$lo[i]:peak.values$hi[i]
        amps <- spg[i, ix]
        peaks$mean.frequency[i] <- weighted.mean(freqs[ix], amps)
        peaks$mean.amplitude[i] <- mean(amps)
        tmp <- range(amps)
        peaks$max.amplitude[i] <- tmp[2]
        peaks$amplitude.range[i] <- diff(tmp)
    }
    return(invisible(peaks))
  }

landmarkacoustics/SoundPoints-R documentation built on May 29, 2019, 9:14 a.m.