【问题标题】:Slew rate measuring转换速率测量
【发布时间】:2013-04-03 09:11:29
【问题描述】:

我必须测量信号的转换率,如下图所示。我需要灰色箭头标记的部分的转换速率。

目前,我使用 hann 窗来平滑信号,以消除最终的噪声并使峰值变平。然后我搜索(从右开始) 30% 和 70% 点并计算这两个点之间的转换率。 但我的问题是,信号在平滑后变得平坦。因此,计算出的压摆率没有达到应有的高。如果我减少平滑,那么峰值(您可以在图像中看到右侧)会变得更高,最终会在错误的位置找到 30% 的点。

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

【问题讨论】:

    标签: numpy scipy signal-processing python-2.5


    【解决方案1】:

    如果您知道信号在什么值之间转换,并且噪声不太大,您可以简单地计算 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()
    

    【讨论】:

    • 非常有趣的方法。但目前我无法理解您的实施。如何获取时间信息?您的信号不包含任何时间值。
    • @wewa 我使用数组中的位置作为时间的代理。如果您的信号以恒定时间步长dt 进行采样,那么您需要做的就是将所有内容乘以得到实际时间。
    • 谢谢,我已经这么想了。但对我来说,你如何计算t30t70idx30idx70idx 并不是很清楚。你能在你的代码中评论这个吗?
    • @wewa 我在该块之前添加了一个冗长的评论,看看它是否有意义。
    猜你喜欢
    • 1970-01-01
    • 2013-08-28
    • 2018-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多