📄 lowpass_iir_digital_filter.m
字号:
%Program to Design the IIR Lowpass Digital Filter According to the Given
%Specifications
%
%Type in the passband edge frequency and the stopband edge frequency(Digital)
wp=input('Passband edge frequency in rad = pi*');
ws=input('Stopband edge frequency in rad = pi*');
%Type in the peak passband ripple and the minimum stopband attenation
Rp=input('Peak passband ripple in dB = ');
Rs=input('Minimum stopband attenation in dB = ');
%Compute the passband edge frequency and the stopband edge frequency(Analog)
Wp=tan(wp*pi/2);disp(sprintf('Wp =%10.7f rad/s',Wp))
Ws=tan(ws*pi/2);disp(sprintf('Ws =%10.7f rad/s',Ws))
disp(sprintf('Rp=%f dB',Rp))
disp(sprintf('Rs=%f dB',Rs))
%Compute the transition ratio
k=Wp/Ws;disp(sprintf('1/k =%10.7f',1/k))
%Compute the discrimination parameter
e=sqrt(1/(10.^(-Rp/10))-1);disp(sprintf('e.^2 =%10.7f',e.^2))
A=sqrt(1/(10.^(-Rs/10)));disp(sprintf('A.^2 =%10.7f',A.^2))
k1=e/sqrt(A.^2-1);disp(sprintf('1/k1 =%10.7f',1/k1))
%Compute the order
N=log10(1/k1)/log10(1/k);disp(sprintf('N =%10.7f',N))
%Compute the 3-dB cutoff frequency
%Apply (5.32a)
Wn1=Wp/(e.^(1/ceil(N)));disp(sprintf('Wc1 =%10.7f rad/s',Wn1))
%Apply (5.32b)
Wn2=Ws/((A.^2-1).^(1/(2*ceil(N))));disp(sprintf('Wc2 =%10.7f rad/s',Wn2))
%Compute the num vector and the den vector of Ha(s)
[num,den]=butter(ceil(N),Wn2,'s');
disp('The num vector of Ha(s) is ');disp(num);
disp('The den vector of Ha(s) is ');disp(den);
%Compute the num vector and the den vector of G(z)
[num1,den1]=bilinear(num,den,0.5);
disp('The num vector of G(z) is ');disp(num1);
disp('The den vector of G(z) is ');disp(den1);
%计算增益响应
[h,omega]=freqz(num1,den1,256);
gain=20*log10(abs(h));
%绘制增益响应
plot(omega/pi,gain);grid
axis([0 1 -40 5]);
xlabel('\omega/\pi');
ylabel('增益,dB');
title('Butterworth低通滤波器的增益响应');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -