1

i have the random data in which i plotted graph for finding the peaks which is originated from zero i used this code

x = np.array([0, 7, 18, 24, 26, 27, 26, 25, 26, 16, 20, 16, 23, 33, 27, 27, 
22, 26, 27, 26, 25, 24, 25, 26, 23, 25, 26, 24, 23, 12, 22, 11, 15, 24, 11, 
12, 11, 27, 19, 25, 26, 21, 23, 26, 13, 9, 22, 18, 23, 26, 26, 25, 10, 22, 
27, 25, 19, 10, 15, 20, 21, 13, 16, 16, 15, 19, 17, 20, 24, 26, 20, 23, 23, 
25, 19, 15, 16, 27, 26, 27, 28, 24, 23, 24, 27, 28, 30, 31, 30, 9, 0, 11, 
16, 25, 25, 22, 25, 25, 11, 15, 24, 24, 24, 17, 0, 23, 21, 0, 24, 26, 24, 
26, 26, 26, 24, 25, 24, 24, 22, 22, 22, 23, 24, 26])
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import find_peaks
zero_locs = np.where(x==0) # find zeros in x
search_lims = np.append(zero_locs, len(x)) # limits for search area

diff_x = np.diff(x) # find the derivative of x
diff_x_mapped = diff_x > 0 # find the max's of x (zero crossover #  points)

# from every zero, search for the first peak within the range of current 
#  zero location to next zero location
peak_locs = []
for i in range(len(search_lims)-1):
peak_locs.append(search_lims[i] + 
np.where(diff_x_mapped[search_lims[i]:search_lims[i+1]]==0)[0][0])

fig= plt.figure(figsize=(19,5))
plt.plot(x)
plt.plot(np.array(peak_locs), x[np.array(peak_locs)], "x", color = 'r')

this is my code actually this is vehicle speed data for every 0 to maximum peak it is detecting correctly but the thing is it should detect above 26 i tried unable to get it. my graph output is for starting point only it is detecting correctly remaining 3 points it should not be detected only the peak value 0 to above 26 only it has to detect how can i do it

desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • See the original post and answer https://stackoverflow.com/questions/74125508/peak-finding-algorithm-using-scipy-python/74127889#74127889. Also, in general, please don't make multiple posts for the same question unless there is a novel difference which requires a new thread. – greenerpastures Oct 20 '22 at 13:58

0 Answers0