If you know between what values your signal is transitioning, and your sounds is not too massive, you can basically compute the time variations among all crossings of 30% and all crossings of 70% and hold the smallest one:
import numpy as np import matplotlib.pyplot as plt s100, s0 = 5, signal = np.concatenate((np.ones((25,)) * s100, s100 + (np.random.rand(twenty five) - .5) * (s100-s0), np.linspace(s100, s0, 25), s0 + (np.random.rand(25) - .5) * (s100-s0), np.types((twenty five,)) * s0)) #
noritake rochelle platinum getaway emphasize Interpolate to discover crossings with thirty% and 70% of signal # The general linear interpolation formulation amongst (x0, y0) and (x1, y1) is: # y = y0 + (x-x0) * (y1-y0) / (x1-x0) # to find the x at which the crossing with y transpires: # x = x0 + (y-y0) * (x1-x0) / (y1-y0) # Due to the fact we are utilizing indices as time, x1-x0 == 1, and if the crossing # takes place inside the interval, then ) & (t70 < 1))[0] t70 = idx70 + t70[idx70] # compute all possible transition times, keep the smallest idx = np.unravel_index(np.argmin(t30[:, None] - t70), (len(t30), len(t70),)) print t30[idx[0]] - t70[idx[1]] # 9.6 plt. plot(signal) plt.plot(t30, [s0 + (s100-s0)*.3]*len(t30), 'go') plt.plot(t30[idx[0]], [s0 + (s100-s0)*.3], 'o', mec='g', mfc='None', ms=10) plt.plot(t70, [s0 + (s100-s0)*.7]*len(t70), 'ro') plt.plot(t70[idx[1]], [s0 + (s100-s0)*.7], 'o', mec='r', mfc='None', ms=10 ) plt.show()