测量方波的上升和下降时间

信息处理 时域 正方形
2022-02-20 07:45:15

我用范围(位,控制某个单元)记录了一个方波。我想测量上升/下降时间,使用python打开和关闭位的时间。我想过使用“衍生” np.diff,但波浪有点吵。我想知道是否有一些有效的技术来实现我的目标。谢谢你,亲爱的社区!

1个回答

如果需要对上升和下降时间进行低噪声高质量估计,一个想法是生成眼图并从中创建平均转换,然后我们可以通过最小化噪声准确地计算出 10%/90%上升和下降时间(或任何稳定的标准)。

否则,如果信号本身没有噪声,则可以使用 确定最小和最大信号以及 10% 和 90% 阈值并确定通过阈值的过渡时间的简单方法numpy.where

下面是我自己的带有调制波形的眼图方法的代码,可以很容易地与一系列脉冲一起使用:

"""
Created on Mon May 20 19:34:28 2019

Eye Diagram Utility

@author: Dan Boschen
"""
import numpy as np
import scipy.signal as sig
import matplotlib.pyplot as plt


def eye(waveform, samp_per_sym, sym_per_win, windows, oversamp=64, plot=True):
    '''
    waveform: data 
    samp_per_sym: # of samples per symbol
    sym_per_win: # of symbols to display in eye diagram
    windows: # of sweeps 
    oversamp: oversampling ratio (default = 64)
    plot: will create eyediagram plot if True (real data only)
    
    returns:
    xaxis: xaxis time values
    eye: eye diagram magnitudes
    '''
    # resample data to emulate continuous waveform
    resamp = int(np.ceil(oversamp/samp_per_sym))
    tx_resamp = sig.resample(waveform, len(waveform) * resamp)
    samp_per_win = oversamp * sym_per_win

    # divide by number of samples per win and then
    # pad zeros to next higher multiple using tx_eye = np.array(tx_shaped),
    # tx_eye.resize(N)

    # N is total number of windows possible
    N = len(tx_resamp)//samp_per_win

    tx_eye = np.array(tx_resamp)
    tx_eye.resize(N * samp_per_win)
    grouped = np.reshape(tx_eye, [N, samp_per_win])
    eye = np.real(grouped.T)

    # create an xaxis in samples np.shape(eye) gives the
    # 2 dimensional size of the eye data and the first element
    # is the interpolated number of samples along the x axis
    nsamps = np.shape(eye)[0]
    xaxis = np.arange(nsamps)/resamp

    if plot:
        plt.figure()
        # plot showing continuous trajectory of
        plt.plot(xaxis, eye[:, :windows])
        # actual sample locations
        plt.plot(xaxis[::resamp], eye[:, :windows][::resamp], 'b.')
        plt.title("Eye Diagram")
        plt.xlabel('Samples')
        plt.grid()
        plt.show()

    return xaxis, eye

或者,此处提供的开源代码稍微复杂一些,但会产生具有持久强度的漂亮图:

眼图

图片来源:https ://scipy-cookbook.readthedocs.io/_static/items/attachments/EyeDiagram/eye-diagram3.png