msExtrema: Find both Local Maxima and Local Minima

Description Usage Arguments Value See Also Examples

Description

Finds both local extrema in a vector, time series, or in each column of a matrix.

Usage

1
msExtrema(x, span=3)

Arguments

x

a vector, time series, or matrix. If x is a matrix, msExtrema finds both local maxima and local minima in each column of x.

span

a numeric value indicating the span of the local extreme. A local maximum (minimum) is defined as an element in a sequence which is greater (smaller) than all other elements within a window of width span centered at that element. The default value is 3, meaning that a maximum (minimum) is bigger (smaller) than both of its neighbors.

Value

a list with two elements:

index.max

an object like x of logical values. Values that are TRUE correspond to local maxima in the data.

index.min

an object like x of logical values. Values that are TRUE correspond to local minima in the data.

See Also

zeroCross.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## create a synthetic sequence 
a<-c(3,3,2,1,1,2,1,2,3,3,1,1,1,3,3,3,2,2,2,1,1,1,1,2,3)

## detect local maxima and minima 
maxmin <- msExtrema(a)

## visualize the result 
par(mfrow=c(1,1))
plot(a, type="l")
points((1:length(a))[maxmin$index.max],
    a[maxmin$index.max], col=2, pch=1)
points((1:length(a))[maxmin$index.min],
    a[maxmin$index.min], col=3, pch=2)
if (!is.R()){
    legend(x=18, y=3, col=2:3, marks=1:2, legend=c("maxima", "minima"))
} else {
    legend(x=18, y=3, col=2:3, pch=1:2, legend=c("maxima", "minima"))
}

zeehio/msProcess documentation built on May 4, 2019, 10:15 p.m.