Peaks.jl
Peaks.argmaxima
— Functionargmaxima(x[, w=1; strict=true])
Find the indices of the local maxima of x
where each maxima i
is either the maximum of x[i-w:i+w]
or the first index of a plateau.
If strict
is true
, all elements of x[i-w:i+w]
or the bounds of a plateau must exist and must not be missing
or NaN
. For strict == false
, a maxima is the maximum or first element of all existing and non-NaN or missing elements in x[i-w:i+w]
or the bounds of a plateau.
See also: findmaxima
, findnextmaxima
Examples
julia> argmaxima([0,2,0,1,1,0])
2-element Vector{Int64}:
2
4
julia> argmaxima([2,0,1,1])
Int64[]
julia> argmaxima([2,0,1,1]; strict=false)
2-element Vector{Int64}:
1
3
Peaks.argminima
— Functionargminima(x[, w=1; strict=false])
Find the indices of the local minima of x
where each minima i
is either the minimum of x[i-w:i+w]
or the first index of a plateau.
If strict
is true
, all elements of x[i-w:i+w]
or the bounds of a plateau must exist and must not be missing
or NaN
. For strict == false
, a minima is the minimum or first element of all existing and non-NaN or missing elements in x[i-w:i+w]
or the bounds of a plateau.
See also: findminima
, findnextminima
Examples
julia> argminima([3,2,3,1,1,3])
2-element Vector{Int64}:
2
4
julia> argminima([2,3,1,1])
Int64[]
julia> argminima([2,3,1,1]; strict=false)
2-element Vector{Int64}:
1
3
Peaks.maxima
— Functionmaxima(x[, w=1; strict=true])
Find the values of the local maxima of x
where each maxima i
is either the maximum of x[i-w:i+w]
or the first index of a plateau.
See also: argmaxima
, findnextmaxima
Peaks.minima
— Functionminima(x[, w=1; strict=true])
Find the values of the local minima of x
where each minima i
is either the minimum of x[i-w:i+w]
or the first index of a plateau.
See also: argminima
, findnextminima
Peaks.findmaxima
— Functionfindmaxima(x[, w=1; strict=true]) -> (idxs, vals)
Find the indices and values of the local maxima of x
where each maxima i
is either the maximum of x[i-w:i+w]
or the first index of a plateau.
See also: argmaxima
, findnextmaxima
Peaks.findminima
— Functionfindminima(x[, w=1; strict=true]) -> (idxs, vals)
Find the indices and values of the local minima of x
where each minima i
is either the minimum of x[i-w:i+w]
or the first index of a plateau.
See also: argminima
, findnextminima
Peaks.peakproms
— Functionpeakproms(peaks, x;
strict=true,
minprom=nothing,
maxprom=nothing
) -> (peaks, proms)
Calculate the prominences of peaks
in x
, filtering peaks with prominences less than minprom
and greater than maxprom
, if either are given.
Peak prominence is the absolute height difference between the current peak and the larger of the two adjacent smallest magnitude points between the current peak and adjacent larger peaks or signal ends.
The prominence for a peak with a NaN
or missing
between the current peak and either adjacent larger peaks will be NaN
or missing
if strict == true
, or it will be the larger of the smallest non-NaN
or missing
values between the current peak and adjacent larger peaks for strict == false
.
See also: findminima
, findmaxima
Examples
julia> x = [0,5,2,3,3,1,4,0];
julia> xpks = argmaxima(x)
3-element Vector{Int64}:
2
4
7
julia> peakproms(xpks, x)
([2, 4, 7], Union{Missing, Int64}[5, 1, 3])
julia> x = [missing,5,2,3,3,1,4,0];
julia> peakproms(xpks, x)
([2, 4, 7], Union{Missing, Int64}[missing, 1, 3])
julia> peakproms(xpks, x; strict=false)
([2, 4, 7], Union{Missing, Int64}[5, 1, 3])
Peaks.peakproms!
— Functionpeakproms!(peaks, x;
strict=true,
minprom=nothing,
maxprom=nothing
) -> (peaks, proms)
Calculate the prominences of peaks
in x
, removing peaks
with prominences less than minprom
or greater than maxprom
, if either are given. Returns the modified peaks and their prominences.
See also: peakproms
, findminima
, findmaxima
Peaks.peakwidths
— Functionpeakwidths(peaks, x, proms;
strict=true,
relheight=0.5,
minwidth=nothing,
maxwidth=nothing
) -> (peaks, widths, leftedge, rightedge)
Calculate the widths of peaks
in x
at a reference level based on proms
and relheight
, removing peaks with widths less than minwidth
or greater than maxwidth
, if either are given. Returns the modified peaks, widths, and the left and right edges at the reference level.
Peak width is the distance between the signal crossing a reference level before and after the peak. Signal crossings are linearly interpolated between indices. The reference level is the difference between the peak height and relheight
times the peak prominence. Width cannot be calculated for a NaN
or missing
prominence.
The width for a peak with a gap in the signal (e.g. NaN
, missing
) at the reference level will match the value/type of the signal gap if strict == true
. For strict == false
, the signal crossing will be linearly interpolated between the edges of the gap.
See also: peakprom
, findminima
, findmaxima
Examples
julia> x = [0,1,0,-1.];
julia> xpks = argmaxima(x)
1-element Vector{Int64}:
2
julia> peakwidths(xpks, x, [1])
([2], [1.0], [1.5], [2.5])
julia> x[3] = NaN;
julia> peakwidths(xpks, x, [1])
([2], [NaN], [1.5], [NaN])
julia> peakwidths(xpks, x, [1]; strict=false)
([2], [1.0], [1.5], [2.5])
Peaks.peakwidths!
— Functionpeakwidths!(peaks, x, proms;
strict=true,
relheight=0.5,
minwidth=nothing,
maxwidth=nothing
) -> (peaks, widths, leftedge, rightedge)
Calculate the widths of peaks
in x
at a reference level based on proms
and relheight
, removing peaks with widths less than minwidth
or greater than maxwidth
, if either are given. Returns the modified peaks, widths, and the left and right edges at the reference level.
See also: peakwidths
, peakproms
, findminima
, findmaxima
Peaks.findnextmaxima
— Functionfindnextmaxima(x, i[, w=1; strict=true])
Find the index of the next maxima in x
after or including i
, where the maxima i
is either the maximum of x[i-w:i+w]
or the first index of a plateau. Returns lastindex(x) + 1
if no maxima occur after i
.
If strict
is true
, all elements in x[i-w:i+w]
or the bounds of a plateau must exist and must not be missing
or NaN
. For strict == false
, a maxima is the maximum or first element of all existing and non-NaN or missing elements in x[i-w:i+w]
or the bounds of a plateau.
See also: argmaxima
Examples
julia> findnextmaxima([0,2,0,1,1,0], 2)
2
julia> findnextmaxima([0,2,0,1,1,0], 3)
4
Peaks.findnextminima
— Functionfindnextminima(x, i[, w=1, strict=true])
Find the index of the next minima in x
after or including i
, where the minima i
is either the minimum of x[i-w:i+w]
or the first index of a plateau. Returns lastindex(x) + 1
if no minima occur after i
.
If strict
is true
, all elements in x[i-w:i+w]
or the bounds of a plateau must exist and must not be missing
or NaN
. For strict == false
, a minima is the minimum or first element of all existing and non-NaN or missing elements in x[i-w:i+w]
or the bounds of a plateau.
See also: argminima
Examples
julia> findnextminima([3,2,3,1,1,3], 2)
2
julia> findnextminima([3,2,3,1,1,3], 3)
4