Learn R Programming

Dimodal (version 1.0.3)

find.flats: Local flat detector.

Description

Locate flat sections, specified by the ripple parameter, within data.

Usage

find.flats(x, fripple, minlen, fminlen, noutlier)

Value

find.flats returns a "Diflat" object. If there are no flats in the data then the result will be empty and have zero rows.

Arguments

x

a vector of real or integer values

fripple

height of flat as fraction (0 -- 1 excl.) of data range

minlen

minimum length of flat, in data points (absolute)

fminlen

minimum length of flat, as fraction (0 -- 1 excl.) of data length (relative)

noutlier

number of points outside the ripple range allowed to either side of source

Details

The detector scans every point in x to find the contiguous range of indices that lie within the ripple centered at the point's value. The algorithm allows noutlier points to each side of the source point (so the total can be twice this), but not as the first or last points. In other words, the endpoints of the flat will be within the ripple specification. Flats must have a length of the larger of minlen or the relative fminlen of length(x), counting that portion not covered by a longer flat. Flats may therefore overlap, but only if the extension meets the length requirement. Flats are reported for their original extent and not the exposed portion.

The algorithm will ignore non-finite values in x, but the endpoints of the features apply to the original, unscreened data.

The arguments correspond to options "flat.fripple", "flat.minlen", "flat.fminlen", and "flat.noutlier". These are provided when called within Dimodal; this function does not access Diopt directly.

This function is not exported from the Dimodal package, but may be useful on its own for any signal. Within Dmodal it is followed by a call to shiftID.place to move indices to the original data grid.

The detector switches its scan algorithms based on the data size. The base approach, which scans outward from each source point, is O(n Lflat) in time and O(n) in memory, where Lflat is the average length of all ranges. This is usually a substantial fraction of the data, a third to half, so the algorithm is essentially O(n^2). For larger data sets it switches to a segtree-based search that has a high overhead. The time complexity is not known, and the memory consumption is still O(n). The second approach runs faster with more than 10 thousand data points, and is an order of magnitude quicker for 100 thousand points.

See Also

Diflat, Diopt, shiftID.place