FindPeaks: Detect Local Extrema

Description Usage Arguments Value Author(s) References Examples

View source: R/FindPeaks.R

Description

Compress a vector (or time series) by extracting only the important local extrema (see references for algorithm implemented).

Usage

1
FindPeaks(a, R, smooth, window = NULL, thres = NULL, na.pad = FALSE)

Arguments

a

Vector of measured values (can be time series or not).

R

Numeric value greater than 1 indicating the threshold for important local extrema. Larger values mean fewer peaks are selected (higher compression ratio). Try starting with 1.1 if you are unsure what value to use.

smooth

Logical, should a moving average filter be applied before extracting local extrema? If TRUE (recommended), this is implemented with the rollmean() function from the zoo package.

window

Numeric, if smooth = TRUE, a value indicating the window of points to be used for moving average filter. Else if smooth = FALSE, this can be left as NULL (the default).

thres

Numeric value indicating that points in a below thres will be dropped. This occurs before any smoothing or detection of local extrema. If thres = NULL (the default), all points will be retained for analysis.

na.pad

Logical, should the compressed (x, y) vectors be padded with NA at the ends to make them the same length as the original data? Useful if you are trying to add a column to a dataframe and need to match the number of existing rows. Then when plotting, you can use na.rm = TRUE to plot only the extrema.

Value

Object of class peaks, a list containing:

indices

Locations of detected peaks.

peaks

y-values for detected peaks.

data

Original data passed to this function.

smooth

If smooth = TRUE, the smoothed data, else NA.

window

If smooth = TRUE, the smoothing window used, else NA.

compr

Compression ratio (1 minus number of peaks detected / length of original vector).

corr

Pearson correlation coefficient between original and compressed vectors.

diff

Mean difference between original and compressed vectors.

Author(s)

Addison Klinke, agk38@case.edu

References

\insertRef

fink_indexing_2004rainflow

Examples

1
2
3
4
5
6
7
8
# Smooth with moving average filter of 120 minutes (2 hours)
# Extract local extrema for temperature time series with R=1.1 threshold
data(weather)
p <- FindPeaks(weather$temp[1:7000], R = 1.1, smooth = TRUE, window = 120)
summary(p)

# Plot the compressed and original time series
plot(p)

addisonklinke/rainflow documentation built on Aug. 23, 2020, 10:48 a.m.