Given a wave or any data consisting of pulses, the code will identify the edges of the pulses and give you the average pulse width.
The data used is from here
The idea is to take the points where the change in slope is maximum (these points will be the pulse edges). We then see how the slope of the data is distributed.
Last but not the least. Finding the average width of these pulses. We can do this by taking the difference between the x component of these points. Add them all up and divide by the total number of pulses.
# Get the final time intervals:
time_intervals = []
for i in range(1,len(selective_x)):
time_diff = selective_x[i]-selective_x[i-1]
time_intervals.append(time_diff)
time_intervals = np.array(time_intervals)
time_intervals.mean()
0.38003271961972585
in my case.
That's it!!
Feel free to drop suggestions.
Thank you