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 asFraction is true, this is multiplied by the total y-axis range (y-range) of the data.

minSlope

The minimum slope between adjacent peaks and troughs. Useful when adjacent peaks and troughs are far apart along the x-axis. If asFraction is true, this is multiplied by the y-range/x-range of the data.

asFraction

Whether to interpret the minYerror, minSlope, edgeFilter, and maxPeakWidth arguments as fractions of the total dimensions of the data (TRUE) or just as absolute values (FALSE)

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 (TRUE) or just compare peaks and troughs to adjacent peaks and troughs (FALSE)

ROI

Region of interest. Specifies the range of x-values that the function sees. Use the format ROI = c(min, max). If this parameter is used, the edgeFilter parameter is ignored.

edgeFilter

Removes peaks and troughs within this distance of the edge of the data set. If asFraction is true, this is multiplied by the x-range of the data. This filter is only applied after the data has been processed.

justPeaks

Whether to return only the peaks (TRUE) or also the troughs (FALSE)

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