What is the output of the following code that finds peaks in a signal array?
import numpy as np from scipy.signal import find_peaks signal = np.array([0, 2, 1, 3, 0, 1, 2, 1, 0]) peaks, _ = find_peaks(signal) print(peaks.tolist())
Peaks are points higher than their immediate neighbors.
The peaks are at indices 1 (value 2), 3 (value 3), and 6 (value 2) because these points are greater than their neighbors.
Given the signal array, how many peaks have a height of at least 3?
import numpy as np from scipy.signal import find_peaks signal = np.array([1, 3, 7, 1, 2, 6, 0, 1]) peaks, properties = find_peaks(signal, height=3) print(len(peaks))
Check which peaks have values >= 3.
Peaks are at indices 2 (7) and 5 (6), both >= 3, so count is 2.
Which plot correctly shows peaks found with a minimum distance of 3 between them?
import numpy as np import matplotlib.pyplot as plt from scipy.signal import find_peaks signal = np.array([0, 2, 1, 3, 0, 1, 2, 1, 0]) peaks, _ = find_peaks(signal, distance=3) plt.plot(signal) plt.plot(peaks, signal[peaks], "x") plt.show()
Minimum distance means peaks must be at least 3 indices apart.
Peaks at indices 1 and 6 are at least 3 apart. Peak at 3 is too close to 1, so it is excluded.
What error does the following code produce?
import numpy as np from scipy.signal import find_peaks signal = [1, 2, 3, 2, 1] peaks, properties = find_peaks(signal, height='high')
Check the type of the height parameter.
The height parameter expects a number or tuple, but a string 'high' is given, causing a ValueError.
Which option correctly finds peaks in the signal that have a height of at least 2 and a prominence of at least 1?
import numpy as np from scipy.signal import find_peaks signal = np.array([0, 2, 1, 3, 0, 1, 2, 1, 0]) peaks, properties = find_peaks(signal, height=2, prominence=1) print(peaks.tolist())
Prominence measures how much a peak stands out from its surroundings.
Peaks at indices 3 and 6 meet both height >= 2 and prominence >= 1 conditions.