我是Python新手,過濾信號時完全卡住了。這是代碼:使用Python lfilter過濾信號
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
fs=105e6
fin=70.1e6
N=np.arange(0,21e3,1)
# Create a input sin signal of 70.1 MHz sampled at 105 MHz
x_in=np.sin(2*np.pi*(fin/fs)*N)
# Define the "b" and "a" polynomials to create a CIC filter (R=8,M=2,N=6)
b=np.zeros(97)
b[[0,16,32,48,64,80,96]]=[1,-6,15,-20,15,-6,1]
a=np.zeros(7)
a[[0,1,2,3,4,5,6]]=[1,-6,15,-20,15,-6,1]
w,h=signal.freqz(b,a)
plt.plot(w/max(w),20*np.log10(abs(h)/np.nanmax(h)))
plt.title('CIC Filter Response')
output_nco_cic=signal.lfilter(b,a,x_in)
plt.figure()
plt.plot(x_in)
plt.title('Input Signal')
plt.figure()
plt.plot(output_nco_cic)
plt.title('Filtered Signal')
而且情節:
正如你可以看到,雖然濾波器的傳遞函數是正確的,輸出不是。而我不明白爲什麼我的代碼無法正常工作。我在Matlab中編碼相同,輸出看起來不錯。
Thaks的幫助!
沒有人?,一個線索? – Alex
這甚至沒有在我的機器上運行,我得到了除零 – Nate