Is there any built-in numpy function to check from which index a signal (array) does not leave a specific error band?
Working with digital filters, I need to determine the length of an impulse response to use in scipy.signal.filtfilt. Fairly easy with Finite Impulse Response (FIR) filters, but kind of impossible with Infinite Impulse Response (IIR) filters.
However, it would do calculating the point, from which the impulse response does not leave a certain error band:

For now I'm using a quick-and-dirty workaround, checking the reversed array manually for the first value outside the error band:
def ringing_time(sig, th):
return len(sig) - np.argmax(np.abs(sig[::-1]) > th)
Is there any fast built-in numpy approach for this?
(sig > th) | (sig < -th)seems faster than computingabs(sig) > theven if it loops over the signal one extra time. There's alsonumpy.isclosewhich requires one loop less, but appears to be slower than the original. - user2379410