matplotlib绘制一阶低通滤波器频率响应

一阶低通滤波器

在这里插入图片描述

H ( j ω ) = u o u i = 1 j ω C R + 1 j ω C = 1 1 + j ω R C H(j\omega )=\frac{u_o}{u_i}=\cfrac{\frac{1}{j\omega C}}{R+\frac{1}{j\omega C}}=\cfrac{1}{1+j\omega RC} H()=uiuo=R+C1C1=1+RC1

截止频率

通常截止频率时输出功率为传导频率的一半,即输出电压为输入电压的 1 / 2 \sqrt{1/2} 1/2
ω 0 = 2 π f 0 = 1 R C \omega_0=2\pi f_0=\frac{1}{RC} ω0=2πf0=RC1时, H ( j ω 0 ) = 1 1 + i = 1 2 ( 1 − i ) H(j\omega_0)=\frac{1}{1+i}=\frac{1}{2}(1-i) H(jω0)=1+i1=21(1i)

幅值: ∣ H ( j ω 0 ) ∣ = 0.5 = − 3 d B |H(j\omega_0)|=\sqrt{0.5}=-3dB H(jω0)=0.5 =3dB
相角: ∠ ∣ H ( j ω 0 ) ∣ = − π 4 ∠|H(j\omega_0)|=-\frac{\pi}{4} ∠∣H(jω0)=4π

Matplotlib绘制频率响应图

matlibplot绘图知识点

  1. matplotlib显示希腊字母
    ‘$\omega$’
  2. matplotlib绘制对数图(半对数线图)
    semilogx(),semilogy()
  3. matplotllib两个不同的Y轴在一张图上一左一右显示
    twinx() 函数
  4. matplotlib设置颜色,标签,线型
  5. matplotlib使用subplots()
  6. matplotlib设置刻度线的颜色,宽度等
    tick_params()
import numpy as np
import matplotlib.pyplot as plt
import control as ctr

R=1e8
C=1e-12
w0=1/R/C
w=np.logspace(0,5,1000)
Hs=1/(1+w*1j*R*C)

fig, ax1 = plt.subplots()
color = 'tab:red'
ax1.set_xlabel('$\omega$')
ax1.set_ylabel('|H(s)| (dB)', color=color)
ax1.semilogx(w, ctr.mag2db(abs(Hs)), color=color)
ax1.tick_params(axis='y', labelcolor=color)
ax1.semilogx(w0, -3, color=color,marker='o')
idx1=np.where(w0<w)
ax1.semilogx([w[0],w[idx1[0][0]]],[-3,-3],'--g')
plt.xlim(1,1e5)
ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis

color = 'tab:blue'
ax2.set_ylabel('Angle', color=color)  # we already handled the x-label with ax1
ax2.semilogx(w, np.angle(Hs), color=color)
ax2.tick_params(axis='y', labelcolor=color)
ax2.semilogx(w0, -np.pi/4, color=color,marker='o')
ax2.semilogx([w0,w0],[0,-np.pi/2],'--g')
ax2.semilogx([w[idx1[0][0]],w[-1]],[-np.pi/4,-np.pi/4],'--g')
fig.tight_layout()  # otherwise the right y-label is slightly clipped
plt.grid()
plt.show()

代码运行结果如下
一阶低通滤波器频率响应
如图所示,设R=1e8,C=1e-12,在截止频率10e4时,频率响应的幅值为-3dB,相角为 − π 4 -\frac{\pi}{4} 4π

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值