bundles / scipy 1.17.1 / scipy / signal / _peak_finding / find_peaks_cwt
function
scipy.signal._peak_finding:find_peaks_cwt
Signature
def find_peaks_cwt ( vector , widths , wavelet = None , max_distances = None , gap_thresh = None , min_length = None , min_snr = 1 , noise_perc = 10 , window_size = None ) Summary
Find peaks in a 1-D array with wavelet transformation.
Extended Summary
The general approach is to smooth vector by convolving it with wavelet(width) for each width in widths. Relative maxima which appear at enough length scales, and with sufficiently high SNR, are accepted.
Parameters
vector: ndarray1-D array in which to find the peaks.
widths: float or sequenceSingle width or 1-D array-like of widths to use for calculating the CWT matrix. In general, this range should cover the expected width of peaks of interest.
wavelet: callable, optionalShould take two parameters and return a 1-D array to convolve with
vector. The first parameter determines the number of points of the returned wavelet array, the second parameter is the scale (width) of the wavelet. Should be normalized and symmetric. Default is the ricker wavelet.max_distances: ndarray, optionalAt each row, a ridge line is only connected if the relative max at row[n] is within
max_distances[n]from the relative max atrow[n+1]. Default value iswidths/4.gap_thresh: float, optionalIf a relative maximum is not found within
max_distances, there will be a gap. A ridge line is discontinued if there are more thangap_threshpoints without connecting a new relative maximum. Default is the first value of the widths array i.e. widths[0].min_length: int, optionalMinimum length a ridge line needs to be acceptable. Default is
cwt.shape[0] / 4, ie 1/4-th the number of widths.min_snr: float, optionalMinimum SNR ratio. Default 1. The signal is the maximum CWT coefficient on the largest ridge line. The noise is
noise_percth percentile of datapoints contained within the same ridge line.noise_perc: float, optionalWhen calculating the noise floor, percentile of data points examined below which to consider noise. Calculated using
stats.scoreatpercentile. Default is 10.window_size: int, optionalSize of window to use to calculate noise floor. Default is
cwt.shape[1] / 20.
Returns
peaks_indices: ndarrayIndices of the locations in the
vectorwhere peaks were found. The list is sorted.
Notes
This approach was designed for finding sharp peaks among noisy data, however with proper parameter selection it should function well for different peak shapes.
The algorithm is as follows:
Perform a continuous wavelet transform on
vector, for the suppliedwidths. This is a convolution ofvectorwithwavelet(width)for each width inwidths. Seecwt.Identify "ridge lines" in the cwt matrix. These are relative maxima at each row, connected across adjacent rows. See identify_ridge_lines
Filter the ridge_lines using filter_ridge_lines.
Array API Standard Support
find_peaks_cwt has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ⛔ ⛔ JAX ⛔ ⛔ Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
import numpy as np from scipy import signal xs = np.arange(0, np.pi, 0.05) data = np.sin(xs) peakind = signal.find_peaks_cwt(data, np.arange(1,10))✓
peakind, xs[peakind], data[peakind]
✗See also
- find_peaks
Find peaks inside a signal based on peak properties.
Aliases
-
scipy.signal.find_peaks_cwt