# findpeaks: Find Peaks In pracma: Practical Numerical Math Functions

## Description

Find peaks (maxima) in a time series.

## Usage

 ```1 2 3``` ```findpeaks(x, nups = 1, ndowns = nups, zero = "0", peakpat = NULL, minpeakheight = -Inf, minpeakdistance = 1, threshold = 0, npeaks = 0, sortstr = FALSE) ```

## Arguments

 `x` numerical vector taken as a time series (no NAs allowed) `nups` minimum number of increasing steps before a peak is reached `ndowns` minimum number of decreasing steps after the peak `zero` can be ‘+’, ‘-’, or ‘0’; how to interprete succeeding steps of the same value: increasing, decreasing, or special `peakpat` define a peak as a regular pattern, such as the default pattern “[+]1,[-]1,”; if a pattern is provided, the parameters `nups` and `ndowns` are not taken into account `minpeakheight` the minimum (absolute) height a peak has to have to be recognized as such `minpeakdistance` the minimum distance (in indices) peaks have to have to be counted `threshold` the minimum `npeaks` the number of peaks to return `sortstr` logical; should the peaks be returned sorted in decreasing oreder of their maximum value

## Details

This function is quite general as it relies on regular patterns to determine where a peak is located, from beginning to end.

## Value

Returns a matrix where each row represents one peak found. The first column gives the height, the second the position/index where the maximum is reached, the third and forth the indices of where the peak begins and ends — in the sense of where the pattern starts and ends.

## Note

On Matlab Central there are several realizations for finding peaks, for example “peakfinder”, “peakseek”, or “peakdetect”. And “findpeaks” is also the name of a function in the Matlab ‘signal’ toolbox.

The parameter names are taken from the “findpeaks” function in ‘signal’, but the implementation utilizing regular expressions is unique and fast.

`hampel`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17``` ```x <- seq(0, 1, len = 1024) pos <- c(0.1, 0.13, 0.15, 0.23, 0.25, 0.40, 0.44, 0.65, 0.76, 0.78, 0.81) hgt <- c(4, 5, 3, 4, 5, 4.2, 2.1, 4.3, 3.1, 5.1, 4.2) wdt <- c(0.005, 0.005, 0.006, 0.01, 0.01, 0.03, 0.01, 0.01, 0.005, 0.008, 0.005) pSignal <- numeric(length(x)) for (i in seq(along=pos)) { pSignal <- pSignal + hgt[i]/(1 + abs((x - pos[i])/wdt[i]))^4 } findpeaks(pSignal, npeaks=3, threshold=4, sortstr=TRUE) ## Not run: plot(pSignal, type="l", col="navy") grid() x <- findpeaks(pSignal, npeaks=3, threshold=4, sortstr=TRUE) points(x[, 2], x[, 1], pch=20, col="maroon") ## End(Not run) ```

### Example output

```         [,1] [,2] [,3] [,4]
[1,] 4.972146  134  118  144
[2,] 4.960051  799  786  817
[3,] 4.590829  257  246  306
```

pracma documentation built on Jan. 30, 2018, 3:01 a.m.