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?
question from:
https://stackoverflow.com/questions/66054603/how-to-detect-the-rising-flank-of-my-trigger-signal-with-as-strided 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…