我有以下框圖和每個子系統,我需要找到 0<=n<=99 的整體脈沖回應。
每個子系統的單個脈沖回應如圖所示。
import numpy as np
import matplotlib.pyplot as plt
n1 = np.arange(0, 6, 1) # set upper limit = 5 and lower limit = 0 in steps of 1.
h1 = [1, 1/2, 1/4, 1/8, 1/16, 1/32] #impulse response h1
plt.stem(n1, h1)
n2 = np.arange(0, 6, 1) # set upper limit = 5 and lower limit = 0 in steps of 1.
h2 = [1, 1, 1, 1, 1, 0] #impulse response h2
plt.stem(n2, h2)
n3 = np.arange(0, 6, 1) # set upper limit = 5 and lower limit = 0 in steps of 1.
h3 = [1/4, 1/2, 1/3, 0, 0, 0] #impulse response h3
plt.stem(n3, h3)
然后我執行了以下卷積和加法以找到整體脈沖回應:
h_t = np.convolve(h1,h2, 'full') h3
但我收到以下錯誤。
ValueError: operands could not be broadcast together with shapes (11,) (6,)
不確定我應該如何合并考慮的 n 值范圍。
uj5u.com熱心網友回復:
您需要填充各種脈沖回應,使它們的形狀匹配。實際上,您顯示的脈沖回應只是非零值。之后,您可以用零填充到無限時間。
def pad(y, t):
return np.pad(y, (0, len(t) - len(y)), constant_values=0)
t = np.arange(20) # or change to 100 for 0<=n<=99, but that's lots of zeros...
h1 = [1, 1/2, 1/4, 1/8, 1/16, 1/32] # impulse response h1
h2 = [1, 1, 1, 1, 1] # impulse response h2
h3 = [1/4, 1/2, 1/3] # impulse response h3
h_t = pad(np.convolve(h1, h2, 'full'), t) pad(h3, t)
# or, equivalently:
t = np.arange(20)
h1 = pad([1, 1/2, 1/4, 1/8, 1/16, 1/32], t) # impulse response h1
h2 = pad([1, 1, 1, 1, 1], t) # impulse response h2
h3 = pad([1/4, 1/2, 1/3], t) # impulse response h3
h_t = np.convolve(h1, h2, 'full')[:len(t)] h3
plt.stem(t, pad(h1, t), markerfmt='C0o')
plt.stem(t, pad(h2, t), markerfmt='C1o')
plt.stem(t, pad(h3, t), markerfmt='C2o')
plt.stem(t, h_t, markerfmt='C3-')
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/391868.html
上一篇:如何繼承帶有細長組件的插槽?
