模型搭建
物理模型
一阶低通滤波器的物理模型来源于一阶RC滤波器,其输出信号与电容的容抗和电阻的阻抗形成的电路网络有关,此电路网络是由电阻分压网络衍生而来。
分压电路输出信号如下:
V o u t = V i n R 2 R 1 + R 2 Vout=Vin\frac{R2}{R1+R2} Vout=VinR1+R2R2
RC滤波电路输出信号如下:
V o u t = V i n X c R 2 + X c 2 = 1 ω C ( 1 ω C ) 2 + R 2 \begin{align*} Vout&=Vin\frac{Xc}{\sqrt{R^2+Xc^2}}\\ &=\frac{\frac{1}{\omega C}}{\sqrt{(\frac{1}{\omega C})^2+R^2}}\\ \end{align*} Vout=VinR2+Xc2Xc=(ωC1)2+R2ωC1
传递函数
一阶低通滤波器传递函数即(这里的 j ω j\omega jω不同于之上的 ω \omega ω, j ω j\omega jω是虚数):
F ( j w ) = V o u t ( j w ) V i n ( j w ) = X c R + X c = 1 j ω C 1 j ω C + R = 1 1 + s R C \begin{align*} F(jw)&=\frac{Vout(jw)}{Vin(jw)}\\ &=\frac{Xc}{R+Xc}\\ &=\frac{\frac{1}{j\omega C}}{\frac{1}{j\omega C}+R}\\ &=\frac{1}{1+sRC}\\ \end{align*} F(jw)=Vin(jw)Vout(jw)=R+XcXc=jωC1+RjωC1=1+sRC1
实际结果就是一阶低通滤波器在系统分析上为一个典型的惯性环节即:
G ( s ) = 1 1 + T s G(s)=\frac{1}{1+Ts} G(s)=1+Ts1
其幅频和相频特性为:
{ A ( ω ) = 1 ( 1 + T 2 ω 2 ) 1 2 φ ( ω ) = − a r c t a n T ω \left\{ \begin{aligned} &A(\omega)=\frac{1}{(1+T^2\omega^2)^\frac{1}{2}}\\ &\varphi(\omega)=-arctanT\omega\\ \end{aligned} \right. ⎩ ⎨ ⎧A(ω)=(1+T2ω2)211φ(ω)=−arctanTω
Simulink波形仿真
参数原理
截止频率
在3dB带宽系统中(即半功率系统),信号幅值增益为-3dB(
20
log
(
0.7079
)
≈
−
3
d
B
20\log(0.7079)\approx-3dB
20log(0.7079)≈−3dB)时的频率为滤波器的截止频率。那么此时输出信号
V
o
u
t
≈
0.7079
V
i
n
Vout\approx0.7079Vin
Vout≈0.7079Vin
那么根据RC滤波器输出信号公式且 ω = 2 π f \omega=2\pi f ω=2πf可得截止频率
0.7079 V i n ≈ V i n X c R 2 + X c 2 0.7079 ≈ 1 ω C ( 1 ω C ) 2 + R 2 0.707 9 2 ≈ ( 1 ω C ) 2 ( 1 ω C ) 2 + R 2 ( 1 ω C ) 2 ≈ 0.707 9 2 1 − 0.707 9 2 R 2 ω ≈ 1 0.707 9 2 1 − 0.707 9 2 R C f c ≈ 1 2 π R C \begin{align*} 0.7079Vin&\approx Vin\frac{Xc}{\sqrt{R^2+Xc^2}}\\ 0.7079&\approx\frac{\frac{1}{\omega C}}{\sqrt{(\frac{1}{\omega C})^2+R^2}}\\ 0.7079^2&\approx\frac{(\frac{1}{\omega C})^2}{(\frac{1}{\omega C})^2+R^2}\\ (\frac{1}{\omega C})^2&\approx\frac{0.7079^2}{1-0.7079^2}R^2\\ {\omega}&\approx\frac{1}{\sqrt{\frac{0.7079^2}{1-0.7079^2}}RC}\\ f_c&\approx\frac{1}{2\pi RC}\\ \end{align*} 0.7079Vin0.70790.70792(ωC1)2ωfc≈VinR2+Xc2Xc≈(ωC1)2+R2ωC1≈(ωC1)2+R2(ωC1)2≈1−0.707920.70792R2≈1−0.707920.70792RC1≈2πRC1
相位延迟
相位延迟在上一节传递函数时其实已经提到,即该模型的相频特性:
φ ( ω ) = − a r c t a n ( ω R C ) = − a r c t a n ( 2 π f R C ) \begin{align*} \varphi(\omega)&=-arctan(\omega RC)\\ &=-arctan(2\pi f RC) \end{align*} φ(ω)=−arctan(ωRC)=−arctan(2πfRC)
算法实现
滤波器离散化
那么实际上一阶低通滤波器就已经可以看作是一阶惯性环节,在数字信号中对一阶惯性环节进行离散化,在向后差分法 Z \mathcal{Z} Z变换中:
s = 1 − z − 1 T s=\frac{1-z^{-1}}{T} s=T1−z−1
则代入传函中可得:
G ( z ) = 1 1 + 1 − z − 1 T R C C ( z ) R ( z ) = 1 1 + 1 − z − 1 T R C R ( z ) = ( C ( z ) + C ( z ) 1 − z − 1 T R C ) R ( z ) = ( 1 + R C T ) − C ( z ) z − 1 R C T C ( z ) = R ( z ) 1 1 + R C T + C ( z ) z − 1 R C T 1 + R C T \begin{align*} G(z)&=\frac{1}{1+\frac{1-z^{-1}}{T}RC}\\ \frac{C(z)}{R(z)}&=\frac{1}{1+\frac{1-z^{-1}}{T}RC}\\ R(z)&=(C(z)+C(z)\frac{1-z^{-1}}{T}RC)\\ R(z)&=(1+\frac{RC}{T})-C(z)z^{-1}\frac{RC}{T}\\ C(z)&=R(z)\frac{1}{1+\frac{RC}{T}}+C(z)z^{-1}\frac{\frac{RC}{T}}{1+\frac{RC}{T}}\\ \end{align*} G(z)R(z)C(z)R(z)R(z)C(z)=1+T1−z−1RC1=1+T1−z−1RC1=(C(z)+C(z)T1−z−1RC)=(1+TRC)−C(z)z−1TRC=R(z)1+TRC1+C(z)z−11+TRCTRC
差分化后:
C ( n ) = R ( n ) 1 1 + R C T + C ( n − 1 ) R C T 1 + R C T = R ( n ) T T + R C + C ( n − 1 ) R C T + R C = R ( n ) T T + R C + C ( n − 1 ) ( T + R C ) − T T + R C = C ( n − 1 ) + ( R ( n ) − C ( n + 1 ) ) T T + R C \begin{align*} C(n)&=R(n)\frac{1}{1+\frac{RC}{T}}+C(n-1)\frac{\frac{RC}{T}}{1+\frac{RC}{T}}\\ &=R(n)\frac{T}{T+RC}+C(n-1)\frac{RC}{T+RC}\\ &=R(n)\frac{T}{T+RC}+C(n-1)\frac{(T+RC)-T}{T+RC}\\ &=C(n-1)+(R(n)-C(n+1))\frac{T}{T+RC}\\ \end{align*} C(n)=R(n)1+TRC1+C(n−1)1+TRCTRC=R(n)T+RCT+C(n−1)T+RCRC=R(n)T+RCT+C(n−1)T+RC(T+RC)−T=C(n−1)+(R(n)−C(n+1))T+RCT
当 lim T → 0 \lim\limits_{T\to 0} T→0lim时, T + R C ≈ R C T+RC\approx RC T+RC≈RC那么上式:
C ( n ) = C ( n − 1 ) + ( R ( n ) − C ( n − 1 ) ) T R C = C ( n − 1 ) + 2 π f T ( R ( n ) − C ( n − 1 ) ) = ( 1 − 2 π f T ) C ( n − 1 ) + ( 2 π f T ) R ( n ) \begin{align*} C(n)&=C(n-1)+(R(n)-C(n-1))\frac{T}{RC}\\ &=C(n-1)+2\pi fT(R(n)-C(n-1))\\ &=(1-2\pi fT)C(n-1)+(2\pi fT)R(n) \end{align*} C(n)=C(n−1)+(R(n)−C(n−1))RCT=C(n−1)+2πfT(R(n)−C(n−1))=(1−2πfT)C(n−1)+(2πfT)R(n)
将 2 π f T 2\pi fT 2πfT转换为系数 α \alpha α。
C语言实现
#define LOW_PASS_FILTERING_ALPHA 0.4f //1~0
typedef struct {
float value_current;
float value_last;
} FOLPF_DATATypeDef;
void FLOAT_FirstOrderLowPassFiltering_Process(FOLPF_DATATypeDef *data_pointer){
data_pointer->value_current=((1-LOW_PASS_FILTERING_ALPHA)*data_pointer->value_last)
+(LOW_PASS_FILTERING_ALPHA *data_pointer->value_current);
data_pointer->value_last=data_pointer->value_current;
}