Type: | Package |
Title: | Peak Finder |
Version: | 0.1.0 |
Description: | This program contains a function to find the peaks and troughs of a data set. It filters the set of peaks to remove noise based on the expected height and expected slope of a peak. Peaks that are too short (caused by random noise), or too shallow (part of the background data) are filtered out. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
Depends: | R (≥ 3.5.0) |
Imports: | dplyr, magrittr, rlang |
RoxygenNote: | 7.2.1 |
Suggests: | knitr, plotly, rmarkdown, testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2025-09-09 21:05:33 UTC; peterpitfield |
Author: | Peter Pitfield [aut, cre] |
Maintainer: | Peter Pitfield <pitfieldp@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2025-09-14 16:30:07 UTC |
Find peaks in a data set
Description
find_peaks
finds the peaks, and troughs if requested, of a data set.
Usage
find_peaks(
dataSet,
xField,
yField,
minYerror = 0.1,
minSlope = 0,
asFraction = TRUE,
maxPeakWidth = Inf,
globalFilter = TRUE,
ROI = c(NA, NA),
edgeFilter = 0.02,
justPeaks = TRUE
)
Arguments
dataSet |
The data to search |
xField |
The name of the field to use as the x-value |
yField |
The name of the field to use as the y-value |
minYerror |
The minimum vertical separation between
adjacent peaks and troughs. If the difference is
less than this, they are filtered out as noise.
If |
minSlope |
The minimum slope between adjacent peaks
and troughs. Useful when adjacent peaks and troughs
are far apart along the x-axis. If |
asFraction |
Whether to interpret the |
maxPeakWidth |
The maximum width a peak can have. Useful for preventing the function from interpreting a long, flat plateau as a peak. |
globalFilter |
Whether to apply the global filter
( |
ROI |
Region of interest. Specifies the range of
x-values that the function sees. Use the format
|
edgeFilter |
Removes peaks and troughs within this
distance of the edge of the data set. If
|
justPeaks |
Whether to return only the peaks ( |
Details
The filter is implemented by comparing pairs of peaks
to a hyperbola determined by the y-intercept (minYerror
),
and the slope (minSlope
). The user can employ either an
edge filter or a region of interest (ROI
) to filter out
certain regions. The difference is that the edge
filter waits for the data to be processed, then
removes the peaks within a certain distance of the edges.
The region of interest lets the user specify a region of the
data, and the function removes everything outside that region
before doing any analysis.
Value
A data frame containing the peaks of the data.
Create array of running totals
Description
sum_line
creates an array of running totals
from an integer array
Usage
sum_line(arr)
Arguments
arr |
The array of integers |
Details
This function takes an array of integers and returns an array with each entry containing the sum of that entry and all previous entries in the input array.
Value
An integer array of running totals.
Global filter for peak finder
Description
write_groups
implements the global filter for the peak finder.
Usage
write_groups(X, Y, minSlope, minYerror, globalFilter = TRUE)
Arguments
X |
x-axis data as array |
Y |
y-axis data as array |
minSlope |
minimum slope between bottom left corner of rectangle and top right corner |
minYerror |
minimum y difference between bottom left corner and top right corner |
globalFilter |
whether the peak finder is actually using this filter. If not, it just returns an array of 0s. |
Details
This filter tests a rectangle bounded by the peaks and troughs in a group, and starting a new group if the rectangle gets too large. The parameters minSlope and minYerror determine how large a rectangle can get.
Value
an integer array containing 1s where the group should be split and 0s otherwise