mirror of
https://gitlab.science.ru.nl/mthesis-edeboone/m-thesis-introduction.git
synced 2024-11-13 10:03:32 +01:00
Simu: add edge detection function
This commit is contained in:
parent
ab20db4ffe
commit
5e4cb0ea83
1 changed files with 18 additions and 0 deletions
|
@ -18,3 +18,21 @@ def rot_vector(phi1=0.12345):
|
||||||
])
|
])
|
||||||
|
|
||||||
return np.cos(unit)
|
return np.cos(unit)
|
||||||
|
|
||||||
|
def detect_edges(threshold, data, rising=True, falling=False):
|
||||||
|
"""
|
||||||
|
Detect rising/falling edges in data, returning the indices
|
||||||
|
of the detected edges.
|
||||||
|
|
||||||
|
https://stackoverflow.com/a/50365462
|
||||||
|
"""
|
||||||
|
|
||||||
|
mask = np.full(len(data), False)
|
||||||
|
|
||||||
|
if rising:
|
||||||
|
mask |= (data[:-1] < threshold) & (data[1:] > threshold)
|
||||||
|
|
||||||
|
if falling:
|
||||||
|
mask |= (data[:-1] > threshold) & (data[1:] < threshold)
|
||||||
|
|
||||||
|
return np.flatnonzero(mask)+1
|
||||||
|
|
Loading…
Reference in a new issue