Finds the local maxima in a vector, or time series,
or in each column of a matrix.
USAGE:
peaks(x, span=3, strict=T)
REQUIRED ARGUMENTS:
x:
a vector, matrix, or time series.
peaks will find the local maxima in each
column of x. Missing values are allowed.
OPTIONAL ARGUMENTS:
span:
a peak is defined as an element in a sequence which is greater than
all other elements within a window of width span centered at that element.
The default value is 3, meaning that a peak is bigger than both of its
neighbors.
strict:
logical flag: if TRUE, an element
must be strictly greater than all other values in its window to be considered
a peak.
VALUE:
an object like x of logical values.
Values that are TRUE correspond to local peaks in the data.
DETAILS:
All elements within a halfspan of the end of
a sequence or within a halfspan of a missing value are FALSE.
# find and plot peaks in spectrum
p <- spectrum(lynx,span=c(3,3), plot=T)
peakfreqs <- p$freq[peaks(p$spec, span=5)]
abline(v=peakfreqs, col=2) # draw vertical lines at peak frequencies
peakfreqs/peakfreqs[1]