实验四 用窗函数法设计FIR滤波器

(三)实验内容

题一:生成四种窗函数:矩形窗、三角窗、汉宁窗、海明窗,并观察其频率响应。

N=20;
window1=(boxcar(N))';
[h1,w1]=freqz(window1,1);
subplot(3,1,1);
plot(window1);
title('矩形窗');
grid on;
db1=20*log10(abs(h1))/ max(abs(h1));
subplot(3,1,2);
plot(w1/pi,db1);title('矩形窗频率响应');
grid on;
pha=angle(h1); 
subplot(3,1,3);
plot(w1/pi,unwrap(pha));
title('矩形窗相频响应');
grid on;
N=20;
window2=(triang(N))';
[h2,w2]=freqz(window2,1);
subplot(3,1,1);
plot(window2);
title('三角窗');
grid on;
db2=20*log10(abs(h2))/max(abs(h2));
subplot(3,1,2);
plot(w2/pi,db2);
title('三角窗频率响应');
grid on;
pha=angle(h2); 
subplot(3,1,3);
plot(w2/pi,unwrap(pha));
title('三角窗相频响应');
grid on;


N=20;
window3=(hann(N))';
[h3,w3]=freqz(window3,1);
subplot(3,1,1);plot(window3);
title('汉宁窗');
grid on;
db3=20*log10(abs(h3))/max(abs(h3));
subplot(3,1,2);plot(w3/pi,db3);
title('汉宁窗响应');
grid on;
pha=angle(h3); 
subplot(3,1,3);
plot(w3/pi,unwrap(pha));
title('汉宁窗相频响应');
grid on;


N=20;
window4=(hamming(N))';
[h4,w4]=freqz(window4,1);
subplot(3,1,1);
plot(window4);
title('海明窗');
grid on;
db4=20*log10(abs(h4))/max(abs(h4));
subplot(3,1,2);
plot(w4/pi,db4);
title('海明窗频率响应');
grid on;
pha=angle(h4); 
subplot(3,1,3);
plot(w4/pi,unwrap(pha));
title('海明窗相频响应');
grid on;


题二:根据下列技术指标,设计一个FIR数字低通滤波器:wp=0.2π,ws=0.4π,ap=0.25dB, as=50dB,选择一个适当的窗函数,确定单位冲激响应,绘出所设计的滤波器的幅度响应。

提示:根据窗函数最小阻带衰减的特性表,可采用海明窗可提供大于50dB的衰减,其过渡带为6.6π/N,因此具有较小的阶次。

<pre name="code" class="plain">clc;
wp=0.2*pi;ws=0.4*pi;ap=0.25;as=50;
wide=ws-wp;             
N=ceil(6.6*pi/wide)+1;       %阶数
n=0:N-1;
wc=(wp+ws)/2;   %截止频率
alpha=(N-1)/2;
hd=sin(wc*(n-alpha))./(pi*(n-alpha));   %低通滤波器的单位冲激响应
subplot(5,1,1);
plot(n,hd);
title('低通滤波器的单位冲激响应');grid on;
windon_ham=(hamming(N))';
subplot(5,1,2);
plot(n,windon_ham);
title('海明窗windon_ham ');
grid on;
y=hd.*windon_ham;  %实际单位脉冲响应
subplot(5,1,3);plot(n,y);title('实际单位脉冲响应y');grid on;
[h,w]=freqz(y,1);
db=20*log10(abs(h))/max(abs(h));
subplot(5,1,4);
plot(w/pi,db);
title('幅度响应(db)');
grid on;
axis([0,1,-100,10]);	
pha=angle(h); 
subplot(5,1,5);
plot(w/pi,unwrap(pha));
title('相频响应');
grid on;


 
 

<p>实验心得:</p><p>1. windon_ham=(hamming(N))'得转置,因为一般我们平时<span style="font-family:Times New Roman;">plot(x,y)</span><span style="font-family:宋体;">的</span><span style="font-family:Times New Roman;">x,y</span><span style="font-family:宋体;">都是横向量</span>;</p><p>2.[h,w]=freqz(window,1)求其响应;</p><p>3.<span style="font-family:宋体;">频率响应的最大值并非在开始除,故需要</span><span style="font-family:Times New Roman;">max(h(w))</span><span style="font-family:宋体;">来求;</span></p><p>4.<span style="font-family:宋体;">相频响应</span><span style="font-family:Times New Roman;">pha,</span><span style="font-family:宋体;">为避免超过</span><span style="font-family:Times New Roman;">pi,</span><span style="font-family:宋体;">故需要</span><span style="font-family:Times New Roman;">unwrap(pha);</span><span style="font-family:宋体;">且需要</span><span style="font-family:Times New Roman;">w/pi</span><span style="font-family:宋体;">,因为默认的是</span><span style="font-family:Times New Roman;">600HZ;</span></p><p>5.<span style="font-family:宋体;">阶数</span><span style="font-family:Times New Roman;">N</span><span style="font-family:宋体;">能大却不能小,否则不满足衰减度</span>。</p>

猜你喜欢

转载自blog.csdn.net/CSDNJay/article/details/46628377