Numpy 回转率测量

Numpy 回转率测量,numpy,scipy,signal-processing,python-2.5,Numpy,Scipy,Signal Processing,Python 2.5,我必须测量信号中的转换率,如下图所示。我需要灰色箭头标记的零件的回转率。 此时,我用汉恩窗平滑了信号,以消除最终的噪音并使峰值变平。然后我搜索(从右开始)30%和70%的点,并计算这两个点之间的回转率。 但我的问题是,信号在平滑后变得平坦。因此,计算出的回转率并没有其应有的高。如果我减少平滑,那么峰值(你可以看到图像右侧)会变得更高,30%的点最终会被发现在错误的位置 是否有更好/更安全的方法来找到所需的转换率?如果您知道信号转换的值,并且噪声不太大,您可以简单地计算30%和70%的所有交叉之

我必须测量信号中的转换率,如下图所示。我需要灰色箭头标记的零件的回转率。

此时,我用汉恩窗平滑了信号,以消除最终的噪音并使峰值变平。然后我搜索(从右开始)30%和70%的点,并计算这两个点之间的回转率。 但我的问题是,信号在平滑后变得平坦。因此,计算出的回转率并没有其应有的高。如果我减少平滑,那么峰值(你可以看到图像右侧)会变得更高,30%的点最终会被发现在错误的位置


是否有更好/更安全的方法来找到所需的转换率?

如果您知道信号转换的值,并且噪声不太大,您可以简单地计算30%和70%的所有交叉之间的时间差,并保持最小值:

import numpy as np
import matplotlib.pyplot as plt

s100, s0 = 5, 0

signal = np.concatenate((np.ones((25,)) * s100,
                         s100 + (np.random.rand(25) - 0.5) * (s100-s0),
                         np.linspace(s100, s0, 25),
                         s0 + (np.random.rand(25) - 0.5) * (s100-s0),
                         np.ones((25,)) * s0))


# Interpolate to find crossings with 30% and 70% of signal
# The general linear interpolation formula between (x0, y0) and (x1, y1) is:
# y = y0 + (x-x0) * (y1-y0) / (x1-x0)
# to find the x at which the crossing with y happens:
# x = x0 + (y-y0) * (x1-x0) / (y1-y0)
# Because we are using indices as time, x1-x0 == 1, and if the crossing
# happens within the interval, then 0 <= x <= 1.
# The following code is just a vectorized version of the above
delta_s = np.diff(signal)
t30 = (s0 + (s100-s0)*.3 - signal[:-1]) / delta_s
idx30 = np.where((t30 > 0) & (t30 < 1))[0]
t30 = idx30 + t30[idx30]
t70 = (s0 + (s100-s0)*.7 - signal[:-1]) / delta_s
idx70 = np.where((t70 > 0) & (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()
将numpy导入为np
将matplotlib.pyplot作为plt导入
s100,s0=5,0
信号=np.串联((np.一个((25,))*s100,
s100+(np.随机兰特(25)-0.5)*(s100-s0),
np.linspace(s100,s0,25),
s0+(np.随机兰特(25)-0.5)*(s100-s0),
np.ones((25,)*s0))
#插值以找到30%和70%信号的交叉点
#(x0,y0)和(x1,y1)之间的一般线性插值公式为:
#y=y0+(x-x0)*(y1-y0)/(x1-x0)
#要查找与y相交的x,请执行以下操作:
#x=x0+(y-y0)*(x1-x0)/(y1-y0)
#因为我们使用指数作为时间,x1-x0==1,如果
#在间隔内发生,然后0)和(t70<1))[0]
t70=idx70+t70[idx70]
#计算所有可能的过渡时间,保持最小
idx=np.Unlavel_索引(np.argmin(t30[:,无)-t70),
(第三十组,第七十组)
打印t30[idx[0]]-t70[idx[1]]
# 9.6
plt。绘图(信号)
平面图(t30,[s0+(s100-s0)*.3]*len(t30),‘go’)
平面图(t30[idx[0]]、[s0+(s100-s0)*.3]、'o',mec='g',mfc='None',ms=10)
平面图(t70,[s0+(s100-s0)*.7]*len(t70),“ro”)
plt.绘图(t70[idx[1]]、[s0+(s100-s0)*.7]、'o',mec='r',mfc='None',ms=10)
plt.show()

非常有趣的方法。但目前我很难理解你的实现。你如何获得时间信息?您的信号不包含任何时间值。@我使用数组中的位置作为时间的代理。如果你的信号是用一个恒定的时间步长来采样的,那么你所需要做的就是把所有的时间乘以它来得到实际的时间。谢谢,我已经想到了。但对我来说,不太清楚如何计算
t30
t70
idx30
idx70
idx
。您能在代码中对此进行注释吗?@wewa我在该块前面添加了一条很长的注释,看看是否有意义。