find_peaks: Get peaks/valleys in waveform data

Description Usage Arguments Value Examples

Description

‘find_peaks' finds peaks or valleys in waveform by using inflection points, with filter of ’n' increasing/decreasing points on both sides of each inflection point.

Usage

1
find_peaks(x, n.points = 3)

Arguments

x

vector of numbers

n.points

the number of decreasing (peaks) or increasing (valleys) data points on left and right of inflection point required to be considered a "peak". A positive number as an input finds peaks, and a negative number finds valleys.

Value

a numeric vector of indices

Examples

1
2
3
4
5
6
7
8
### Format data frame
df.new <- format_data(GCaMP)

### How many peaks are there in trial 1 with 10 decreasing data points on each side?
peak.indices <- find_peaks(df.new$Trial1, n.points = 10)

### When do they occur?
data.frame(times = df.new$Time[peak.indices], vals = df.new$Trial1[peak.indices])

Example output

       times   vals
1  -3.921400 82.794
2  -3.734600 82.752
3  -3.567500 82.700
4  -3.233200 82.896
5  -3.017000 82.756
6  -2.800700 82.687
7  -2.368200 82.941
8  -1.906100 82.747
9  -1.463800 83.235
10 -1.237700 83.008
11 -0.579020 83.365
12 -0.018688 82.841
13  0.207410 82.280
14  0.413850 82.198
15  0.777570 82.782
16  1.092100 82.690
17  1.328100 82.829
18  1.662300 82.326
19  1.878600 82.537
20  2.212800 82.822
21  2.340600 82.889
22  2.615900 83.000
23  2.851800 83.047
24  3.038600 82.930
25  3.254800 82.540
26  3.677500 81.953
27  3.913500 82.790

GCalcium documentation built on May 2, 2019, 9:31 a.m.