|
| 1 | +--- |
| 2 | +Title: '.find_peaks()' |
| 3 | +Description: 'Finds the indices of local maxima (peaks) in a 1D signal array based on specified conditions.' |
| 4 | +Subjects: |
| 5 | + - 'Machine Learning' |
| 6 | + - 'Data Visualization' |
| 7 | +Tags: |
| 8 | + - 'Scikit-learn' |
| 9 | + - 'Machine Learning' |
| 10 | +CatalogContent: |
| 11 | + - 'learn-python-3' |
| 12 | + - 'paths/computer-science' |
| 13 | +--- |
| 14 | + |
| 15 | +In SciPy, the **`.find_peaks()`** function identifies the indices of local maxima (peaks) in a 1D signal array based on specified conditions. |
| 16 | + |
| 17 | +## Syntax |
| 18 | + |
| 19 | +```pseudo |
| 20 | +scipy.signal.find_peaks(x, height=None, threshold=None, distance=None, prominence=None, width=None, wlen=None, rel_height=0.5, plateau_size=None) |
| 21 | +``` |
| 22 | + |
| 23 | +- `x`: The input data in which to search for peaks. |
| 24 | +- `height` (Optional): Specifies the required height of peaks. |
| 25 | +- `threshold` (Optional): The vertical distance to the neighboring samples. |
| 26 | +- `distance` (Optional): Minimum horizontal distance (in samples) between neighboring peaks. |
| 27 | +- `prominence` (Optional): Minimum prominence of peaks. |
| 28 | +- `width` (Optional): Required width of peaks in samples. |
| 29 | +- `wlen` (Optional): Used for calculating the prominence of peaks; specifies the size of the window. |
| 30 | +- `rel_height` (Otional): Used for measuring the width at relative height. |
| 31 | +- `plateau_size` (Optional): Specifies the size of flat peaks (plateaus). |
| 32 | + |
| 33 | +## Example |
| 34 | + |
| 35 | +The following example showcases the `.find_peaks()` function: |
| 36 | + |
| 37 | +```py |
| 38 | +import numpy as np |
| 39 | +from scipy.signal import find_peaks |
| 40 | + |
| 41 | +# Create a signal with some peaks |
| 42 | +signal = np.array([1, 2, 3, 4, 5, 4, 3, 2, 1]) |
| 43 | + |
| 44 | +# Find the peaks in the signal |
| 45 | +peaks, _ = find_peaks(signal) |
| 46 | + |
| 47 | +# Print the indices of the peaks |
| 48 | +print(peaks) |
| 49 | +``` |
| 50 | + |
| 51 | +The code above generates the following output: |
| 52 | + |
| 53 | +```shell |
| 54 | +[4] |
| 55 | +``` |
0 commit comments