Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:IIR过滤器响应_Python_Filter - Fatal编程技术网

Python:IIR过滤器响应

Python:IIR过滤器响应,python,filter,Python,Filter,这与以下方面有关,但本身就是一个问题: 在40MHz采样时,我创建了一个窄带IIR滤波器,其中心频率为1MHz,BW为20kHz。这给出了以下系数- Fc = 1e6 /40e6 # Fcenter as a fraction of Fsample BW = 20e3/40e6 # BW as a fraction of Fsample a0 = 0.00140 a2 = 0.00018 b1 = 1.97241 b2 = -0.9970 如下图所示,应用信号似乎有效-我的问题是: 如

这与以下方面有关,但本身就是一个问题: 在40MHz采样时,我创建了一个窄带IIR滤波器,其中心频率为1MHz,BW为20kHz。这给出了以下系数-

Fc = 1e6 /40e6 # Fcenter as a fraction of Fsample 
BW = 20e3/40e6 # BW as a fraction of Fsample 

a0 = 0.00140
a2 = 0.00018

b1 = 1.97241
b2 = -0.9970
如下图所示,应用信号似乎有效-我的问题是: 如何在python中绘制幅值和相位响应? [根据我之前的帖子,这是故意惯用的]

import numpy as np
import matplotlib.pyplot as plt

# create an array of 1024 points sampled at 40MHz
# [each sample is 25ns apart and the key signal is 1MHz]
Fs = 40e6
T  = 1/Fs
t  = np.arange(0,(1024*T),T)

f     = 1e6   
Omega = 2*np.pi*f
x  = np.sin(Omega*t) * (t**3) * np.exp(-t/2e-6)
x /= max(x)
y  = [0]*len(x)

# create a narrow passband IIR filter with fcentre=1MHz
# and BW=0.0005
Fc = 1e6
Ft = Fc/Fs
BW = 0.0005
R  = 1 - (3*BW)
K  = (1 - 2*R*np.cos(2*np.pi*Ft) + (R*R)) / (2 - 2*np.cos(2*np.pi*Ft))

# coefficients
a0 = 1 - K
a1 = 2*(K-R)*np.cos(2*np.pi*Ft)
a2 = (R*R) - K
b1 = 2*R*np.cos(2*np.pi*Ft)
b2 = -(R*R)

for n in range(2, len(x)):
    y[n] = a0*x[n] + a1*x[n-1] + a2*x[n-2] + b1*y[n-1] + b2*y[n-2]
y /= max(y)

plt.subplot(211)
plt.plot( x,'r-', linewidth=2)
plt.xlabel( 'sample length' )
plt.ylabel( 'ip value' )
plt.grid()

plt.subplot(212)
plt.plot( y,'k-', linewidth=2)
plt.xlabel( 'sample length' )
plt.ylabel( 'op value' )
plt.grid()
plt.show()


也许scipy.signal.freqz函数可以在这里帮助您


我想我能回答这个问题,但要到今晚晚些时候才能回答。你问有趣的问题!