I have a square signal using the following code. How can I count the rising edges using python?
from scipy import signal import numpy as np import matplotlib.pyplot as plot t = np.linspace(0, 1, 1000, endpoint=True) plt.plot(t, signal.square(2 * np.pi * 5 * t))
Following image represents my output:
Advertisement
Answer
If your data is super clean (like the signal provided), then just find the number of occurrences when the value is greater than the previous:
np.sum(np.diff(s) > 0) # 5