您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python中的矩形脉冲序列

Python中的矩形脉冲序列

如果您只是在寻找周期性脉冲序列,例如您所给的示例,那么这是一个脉冲序列,该脉冲序列打开5个周期,然后关闭5个周期:

N = 100 # sample count
P = 10  # period
D = 5   # width of pulse
sig = np.arange(N) % P < D

给予

plot(sig)

情节(签名)

您可以np.arange(N)linspace这里替换。请注意,这不 等于 您的代码,因为脉冲未居中。

这是一个完全可配置的脉冲序列:

def rect(T):
    """create a centered rectangular pulse of width $T"""
    return lambda t: (-T/2 <= t) & (t < T/2)

def pulse_train(t, at, shape):
    """create a train of pulses over $t at times $at and shape $shape"""
    return np.sum(shape(t - at[:,np.newaxis]), axis=0)

sig = pulse_train(
    t=np.arange(100),              # time domain
    at=np.array([0, 10, 40, 80]),  # times of pulses
    shape=rect(10)                 # shape of pulse
)

给予:

可配置的脉冲序列

我认为这是matlabpulsetran函数比用python单行实现更混乱的情况之一,这可能就是scipy不提供它的原因。

python 2022/1/1 18:49:56 有675人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶