Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

python 3.x - How to detect the rising flank of my trigger signal with as_strided?

I process data from my measurement system and use the data shown below as my trigger signal for further data processing. Please find the data file in numpy format here. Currently I use this code to detect the rising flank of the trigger:

def find_rising_flanks(data: np.ndarray) -> np.ndarray:
    mask = (data >= MAX_SENSOR_READOUT)
    # count the number of times the value is below thresh in the window
    below_thresh = np.sum([mask[i:len(mask) - WINDOW_SIZE + i] for i in range(WINDOW_SIZE)], axis=0)
    idx_mask = below_thresh == WINDOW_SIZE
    rising_flanks = np.where(idx_mask[1:] & (~idx_mask[:-1]))[0] + WINDOW_SIZE + 1
    return rising_flanks

However with this code it is possible to find flanks in the first block (between 0 and 600 in the plot), while I would really want the first rising flank at ~1600. The distinct difference is, that there are several samples without -inf or inf, before several "normal numbers" and then several inf samples. So I would guess that i needed to search for a window with "not -inf and not inf" and then for a window full of "inf".

Someone suggested that as_strided could be a better solution for bigger windows. How would that work?

trigger signal

question from:https://stackoverflow.com/questions/66054603/how-to-detect-the-rising-flank-of-my-trigger-signal-with-as-strided

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...