Skip to content

dspk.ops.peaks

Peak candidates on the device.

candidates Local extrema of every channel that reach the channel’s height.
candidates(
data,
heights,
*,
polarity: str = 'positive',
runtime: str | None = None,
) -> dict[str, np.ndarray]

Local extrema of every channel that reach the channel’s height.

Strict on the left (x[t-1] < x[t] >= x[t+1]): a flat peak is reported at its first sample; the first and last samples are never peaks.

Parameters

  • data : array_like
    Signal (channels, samples). float32, int8, int16, uint16 and int32 arrays go to the device as they are and are converted there; other dtypes and lists become float32 first.
  • heights : float or array_like
    Height per channel (channels,), or one value for all.
  • polarity : {"positive", "negative", "both"}, default 'positive'
    "positive": maxima >= height. "negative": minima <= -height. "both": either.
  • runtime : str, default None
    A runtime from runtime.available ("cuda", "hip", "wgpu", "cpu") for this call. By default: the one chosen with runtime.set, else DSPK_RUNTIME, else the first available (GPUs first).

Returns

  • dict of np.ndarray — "channel", "sample" and "value" of every peak, ordered by channel then sample.

Raises

  • ValueError: For an unknown polarity, heights of another length than the channels, or data not 2-D.
  • RuntimeError: When the runtime has no device.

Examples

>>> import numpy as np
>>> import dspk
>>> x = np.random.default_rng(0).standard_normal((4, 30_000)).astype(np.float32)
>>> noise = dspk.ops.math.channel_noise_std(x)
>>> peaks = dspk.ops.peaks.candidates(x, 4 * noise, polarity="negative")