gpt4 book ai didi

Python:IIR 滤波器响应

转载 作者:太空宇宙 更新时间:2023-11-04 01:17:39 29 4
gpt4 key购买 nike

这与 this post 有关但它本身就是一个问题:在 40MHz 采样,我创建了一个窄带 IIR 滤波器,它的中心频率为 1MHz,带宽为 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 中绘制幅度和相位响应?[根据我之前的帖子,这是故意惯用的]

enter image description here

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()

最佳答案

关于Python:IIR 滤波器响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23368427/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com