阶跃函数的卷积和指数衰减

问题描述 投票:1回答:1

我正在尝试将以下公式应用于我的数据:

其中A = 0.3,B = 1,lambda_pb = 0.000431062,lambda_bi = 0.000580525。

时间t,我有:

t=np.array([0, 900, 1800, 2700, 3600, 4500, 5400, 6300, 7200, 8100])

和f(t):

f=np.array([ 0., 0., 0.00555556, 0., 0., 0., 0., 0., 0., 0.])

对于G(t):

G=np.array([ 1., 0.69255058,  0.47822256,  0.32940846, 0.22642738,  0.15536312,  0.10643991,  0.07282715,  0.04977304,  0.03398402])

然后我使用以下代码对G(t)和f(t)进行卷积:

import numpy as np
from numpy import convolve
convolution=np.convolve(f, G)[:len(t)]*(t[1]-t[0])

我得到以下图:enter image description here对于t <tau,我得到红色的曲线。然而,这是不正确的,因为对于t <tau,G(t-tau)= 0(因果关系原理)。因此,我想获得黑色曲线(t = tau处的垂直增加)。任何人都可以告诉我如何改进我的代码来做到这一点,只考虑t> tau的响应函数G(t-tau)?也许使用阶梯函数?

python numpy matplotlib convolution
1个回答
0
投票

是关于情节的问题?

我对你的公式一无所知,但卷积结果对我来说很好。但是,对于数据[0,0,0.00555556 ...],plt.plot将绘制这样的曲线。 plt.step可以解决这个问题

plt.step(t[:3], convolution[:3], where='post', color='r')
plt.plot(t[2:], convolution[2:], color='r')

或者,如果可以的话,重新采样也可以减轻它

def G(t):
    term1 = A * lambda_bi / (lambda_bi - lambda_pb) 
    term2 = np.exp(-lambda_pb * t) - np.exp(-lambda_bi * t)
    term3 = B * np.exp(-lambda_bi * t)
    return term1 * term2 + term3

t = np.linspace(0, 8100, 811)

f = np.zeros(t.shape)
f[t==1800] = 0.00555556

g = G(t)

conv = np.convolve(f, g)[:len(t)]*(t[1]-t[0])
plt.plot(conv)
© www.soinside.com 2019 - 2024. All rights reserved.