目录
一、实验目的
二、实验原理
2.1 概念辨析
2.2 代码实现逻辑与工具函数
三、实验内容
3.1 设计带通滤波器(电平组合法,(理想宽带低通-理想窄带低通)x窗函数)
3.2 高通滤波器((全通零相位- 理想低通滤波器)x窗函数)
3.3 带阻滤波器(电平组合,(理想低通+高通)x窗函数)
四、接口函数
五、实验结果
一、实验目的
(1)加深对数字滤波器的常用指标理解;
(2)学习有限冲激响应数字滤波器的设计方法,重点掌握窗函数设计法。
二、实验原理
2.1 概念辨析
2.2 代码实现逻辑与工具函数
三、实验内容
注意:在数字FIR滤波器设计的过程中,通带峰值起伏不作为参数指标纳入考虑范围。
3.1 设计带通滤波器(电平组合法,(理想宽带低通-理想窄带低通)x窗函数)
3.2 高通滤波器((全通零相位(
)- 理想低通滤波器)x窗函数)
设计线性相位高通FIR滤波器,指标为:
采用窗函数法设计出具有最小长度的线性相位FIR滤波器,并画出滤波器的幅频和相位响应;
3.3 带阻滤波器(电平组合,(理想低通+高通)x窗函数)
设计线性相位带阻FIR滤波器,其性能指标为:采样频率Fs=20kHz,通带截止频率分别为:Fp1=2kHz、Fp2=8kHz,阻带截止频率分别为:Fs1=3kHz、Fs2=6kHz,通带波纹容限为,阻带波纹容限为
。采用窗函数法设计出具有最小长度的线性相位FIR滤波器,并画出滤波器的幅频和相位响应。
四、接口函数
(1)带通滤波器
function []=FIR_bp1(points)
% 1低带宽低通滤波器,2高带宽低通滤波器
M1=21;
M2=32;
w1=0.375*pi;
w2=0.7*pi;
n1=(-M1:M1);
n2=(-M2:M2);
% t_window=0.5+0.5*cos(2*pi/(length(n1))*n1);
t_window1=[zeros(1,M2-M1) hanning(2*M1+1).' zeros(1,M2-M1)];
t_window2=hanning(2*M2+1).';
lp1=[zeros(1,M2-M1) sin(w1*n1)./(pi*n1) zeros(1,M2-M1)];
lp1(M2+1)=w1/pi;
lp2=sin(w2*n2)./(pi*n2);lp2(M2+1)=w2/pi;lp=lp2-lp1;% 代码编写不需要考虑shift
filter1=t_window1.*lp1;
filter2=t_window2.*lp2;% 思路2:先频域卷积后频域反转,标准可不统一
% filter=filter2-filter1;% 思路1:先频域反转后频域卷积,标准须统一
filter=lp.*t_window2;
if points>2*M2+1filter=[lp.*t_window2 zeros(1,points-2*M2-1)];
endfigure();
subplot(3,1,1);
plot(0:length(filter)-1,filter);
xlabel('n');
ylabel('1');Freq_Res=fft(filter);
subplot(3,1,2);
plot(0:2/length(filter):2-2/length(filter),abs(Freq_Res),'b');
xlabel('\pi (rad/s)');
ylabel('1');subplot(3,1,3);
plot(0:2/length(filter):2-2/length(filter),angle(Freq_Res),'b');
xlabel('\pi (rad/s)');
ylabel('rad');
end
(2)高通滤波器
function []=FIR_hp1(points)% 最小阻带衰减 60dB,布莱克曼窗% 5.56π/M<=0.2πM=28;n=-M:M;t_window=blackman(2*M+1).';wc=0.6*pi;hp1=-sin(wc*n)./(pi*n);hp1(M+1)=1-wc/pi;% hp1(M+1)=0.4;hp_filter=hp1.*t_window;if points>2*M+1hp_filter=[hp1.*t_window zeros(1,points-2*M-1)];endFreq_Res=fft(hp_filter);figure();subplot(3,1,1);plot(0:length(hp_filter)-1,hp_filter);xlabel('n');ylabel('1');subplot(3,1,2);plot(0:2/length(hp_filter):2-2/length(hp_filter),abs(Freq_Res),'b');xlabel('\pi (rad/s)');ylabel('1');subplot(3,1,3);plot(0:2/length(hp_filter):2-2/length(hp_filter),angle(Freq_Res),'b');xlabel('\pi (rad/s)');ylabel('rad');
end
(3)带阻滤波器
function []=FIR_bs1(points)% 最小阻带衰减 46.02dB,哈明窗% 3.32π/M<=(1/20)*2πM=34;n=-M:M;t_window=hamming(2*M+1).';wc1=0.25*pi;wc2=0.7*pi;lp1=sin(wc1*n)./(pi*n);lp1(M+1)=wc1/pi;hp1=-sin(wc2*n)./(pi*n);hp1(M+1)=1-wc2/pi;% hp1(M+1)=0.3;bs_filter=(lp1+hp1).*t_window;if points>2*M+1bs_filter=[(lp1+hp1).*t_window zeros(1,points-2*M-1)];endFreq_Res=fft(bs_filter);figure();subplot(3,1,1);plot(0:length(bs_filter)-1,bs_filter);xlabel('n');ylabel('1');subplot(3,1,2);plot(0:2/length(bs_filter):2-2/length(bs_filter),abs(Freq_Res),'b');xlabel('\pi (rad/s)');ylabel('1');subplot(3,1,3);plot(0:2/length(bs_filter):2-2/length(bs_filter),angle(Freq_Res),'b');xlabel('\pi (rad/s)');ylabel('rad');
end
五、实验结果
Figure 1 实验设计的带通/带阻/高通滤波器(指标参考实验内容)