1.»ùÓÚ¾ØÐδ°µÄFIRÊý×ÖµÍͨÂ˲¨Æ÷Éè¼Æ ²ÎÊýÈçÏ£º
Ö÷³ÌÐò£º% »ùÓÚ¾ØÐδ°µÄFIRÊý×ÖµÍͨÂ˲¨Æ÷Éè¼Æ wp=2*pi*1.75/15; ws=2*pi*3.25/15 w=(wp+ws)/2;
N=ceil(4*pi/(ws-wp)); n=0:1:(N-1); alpha=(N-1)/2; m=n-alpha+eps;
hd=sin(w*m)./(pi*m); %µÃµ½ÀíÏëµÍͨÂ˲¨Æ÷ B=boxcar(N);
string=['Boxcar,N=',num2str(N)]; h=hd.*(B)'; %µÃµ½FIRÊý×ÖÂ˲¨Æ÷
[H,w]=freqz(h,[1],1024); %ÇóÆäƵÂÊÏìÓ¦ db=20*log10(abs(H)+eps); %µÃµ½·ùÖµ pha=angle(H); %µÃµ½Ïàλ figure(1); subplot(2,2,1); stem(n,h,'r');
axis([0,N-1,-0.1,0.35]); xlabel('n'); ylabel('h(n)');
title('ʵ¼ÊµÍͨÂ˲¨Æ÷µÄh(n)'); text((0.3*N),0.275,string); subplot(2,2,2); plot(w/pi,db,'r'); axis([0,1,-100,5]); xlabel('w/pi'); ylabel('dB');
title('Ë¥¼õÌØÐÔ(dB)'); grid;
subplot(2,2,3); plot(w,pha); hold on;
plot(0:4,zeros(5),'k'); title('ÏàÆµÌØÐÔ'); xlabel('ƵÂÊ(rad)'); ylabel('Ïàλ(rad)'); axis([0,3.2,-4,4]); subplot(2,2,4); plot(w,abs(H)); title('ƵÂÊÌØÐÔ');
xlabel('ƵÂÊW(rad)'); ylabel('·ùÖµ');
axis([0,3.15,0,1.5]); text(0.9,1.3,string);
2.»ùÓÚ¾ØÐδ°µÄ´øÍ¨Â˲¨Æ÷µÄÉè¼Æ ²ÎÊýÈçÏ£º
×Ó³ÌÐò£º
function hd=ideal_bs(Wcl,Wch,N) alpha=(N-1)/2; n=0:1:N-1;
m=n-alpha+eps;
hd=[sin(Wch*m)-sin(Wcl*m)]./(pi*m);
function hd=ideal_bs(Wcl,Wch,N) alpha=(N-1)/2; n=0:1:N-1;
m=n-alpha+eps;
hd=[sin(Wch*m)-sin(Wcl*m)]./(pi*m);
Ö÷³ÌÐò£º
clear all;
Wph=2*pi*4.75/15; Wpl=2*pi*2.5/15; Wsl=2*pi/15;
Wsh=2*pi*6.25/15;
tr_width=min((Wpl-Wsl),(Wsh-Wph)); %¹ý¶É´ø¿í¶È N=ceil(4*pi/tr_width); %Â˲¨Æ÷³¤¶È n=0:1:N-1;
Wcl=(Wsl+Wpl)/2; %ÀíÏëÂ˲¨Æ÷µÄ½ØÖ¹ÆµÂÊ
Wch=(Wsh+Wph)/2;
hd=ideal_bs(Wcl,Wch,N); %ÀíÏëÂ˲¨Æ÷µÄµ¥Î»³å»÷ÏìÓ¦
w_ham=(boxcar(N))';
string=['¾ØÐδ°','N=',num2str(N)];
h=hd.*w_ham; %½ØÈ¡È¡µÃʵ¼ÊµÄµ¥Î»Âö³åÏìÓ¦
[db,mag,pha,w]=freqz_m2(h,[1]); %¼ÆËãʵ¼ÊÂ˲¨Æ÷µÄ·ù¶ÈÏìÓ¦
subplot(3,2,1);stem(n,hd);title('ÀíÏëÂö³åÏìÓ¦hd(n)') axis([-1,N,-0.5,0.8]);xlabel('n');ylabel('hd(n)'); subplot(3,2,2);stem(n,w_ham);axis([-1,N,0,1.1]); xlabel('n');ylabel('w(n)');text(1.5,1.3,string); subplot(3,2,3);stem(n,h);title('ʵ¼ÊÂö³åÏìÓ¦h(n)'); axis([0,N,-1.4,1.4]);xlabel('n');ylabel('h(n)'); subplot(3,2,4);plot(w,pha);title('ÏàÆµÌØÐÔ');
axis([0,3.15,-4,4]);xlabel('ƵÂÊ£¨rad£©');ylabel('Ïà루?£©'); subplot(3,2,5);plot(w/pi,db);title('·ù¶ÈÌØÐÔ£¨dB£©'); axis([0,1,-80,10]);xlabel('ƵÂÊ£¨pi£©');ylabel('·Ö±´Êý'); subplot(3,2,6);plot(w,mag);title('ƵÂÊÌØÐÔ')
axis([0,3.15,0,1.5]);xlabel('ƵÂÊ£¨rad£©');ylabel('·ùÖµ');
fs=15000;
t=(0:100)/fs;
x=sin(2*pi*t*750)+sin(2*pi*t*5000)+sin(2*pi*t*6100); q=filter(h,1,x); [a,f1]=freqz(x); f1=f1/pi*fs/2; [b,f2]=freqz(q); f2=f2/pi*fs/2; figure(2);
subplot(2,1,1); plot(f1,abs(a));
title('ÊäÈ벨ÐÎÆµÆ×ͼ');
xlabel('ƵÂÊ');ylabel('·ù¶È') subplot(2,1,2); plot(f2,abs(b));
title('Êä³ö²¨ÐÎÆµÆ×ͼ');
xlabel('ƵÂÊ');ylabel('·ù¶È')
3.»ùÓÚ¾ØÐδ°µÄFIRÊý×Ö´ø×èÂ˲¨Æ÷Éè¼Æ ²ÎÊý£º
Ö÷³ÌÐò£º clear all;
Wph=2*pi*6.25/15; Wpl=2*pi/15; Wsl=2*pi*2.5/15; Wsh=2*pi*4.75/15;
tr_width=min((Wsl-Wpl),(Wph-Wsh));%¹ý¶É´ø¿í¶È N=ceil(4*pi/tr_width);%Â˲¨Æ÷³¤¶È n=0:1:N-1;
Wcl=(Wsl+Wpl)/2;%ÀíÏëÂ˲¨Æ÷µÄ½ØÖ¹ÆµÂÊ Wch=(Wsh+Wph)/2;
hd=ideal_bs(Wcl,Wch,N);%ÀíÏëÂ˲¨Æ÷µÄµ¥Î»³å»÷ÏìÓ¦ w_ham=(boxcar(N))';
string=['¾ØÐδ°','N=',num2str(N)]; h=hd.*w_ham;%½ØÈ¡È¡µÃʵ¼ÊµÄµ¥Î»Âö³åÏìÓ¦
[db,mag,pha,w]=freqz_m2(h,[1]);%¼ÆËãʵ¼ÊÂ˲¨Æ÷µÄ·ù¶ÈÏìÓ¦ delta_w=2*pi/1000;
subplot(3,2,1);stem(n,hd);title('ÀíÏëÂö³åÏìÓ¦hd(n)') axis([-1,N,-0.5,0.8]);xlabel('n');ylabel('hd(n)'); subplot(3,2,2);stem(n,w_ham);axis([-1,N,0,1.1]);
xlabel('n');ylabel('w(n)');text(1.5,1.3,string);
subplot(3,2,3);stem(n,h);title('ʵ¼ÊÂö³åÏìÓ¦h(n)'); axis([0,N,-1.4,1.4]);xlabel('n');ylabel('h(n)'); subplot(3,2,4);plot(w,pha);title('ÏàÆµÌØÐÔ');
axis([0,3.15,-4,4]);xlabel('ƵÂÊ£¨rad£©');ylabel('Ïà루¦µ£©'); subplot(3,2,5);plot(w/pi,db);title('·ù¶ÈÌØÐÔ£¨dB£©');
axis([0,1,-80,10]);xlabel('ƵÂÊ£¨pi£©');ylabel('·Ö±´Êý'); subplot(3,2,6);plot(w,mag);title('ƵÂÊÌØÐÔ')
axis([0,3,0,2]);xlabel('ƵÂÊ£¨rad£©');ylabel('·ùÖµ');
fs=15000; t=(0:100)/fs;
x=sin(2*pi*t*750)+sin(2*pi*t*3000)+sin(2*pi*t*6100); q=filter(h,1,x); [a,f1]=freqz(x); f1=f1/pi*fs/2; [b,f2]=freqz(q); f2=f2/pi*fs/2; figure(2);
subplot(2,1,1); plot(f1,abs(a));
title('ÊäÈ벨ÐÎÆµÆ×ͼ');
xlabel('ƵÂÊ');ylabel('·ù¶È') subplot(2,1,2); plot(f2,abs(b));
title('Êä³ö²¨ÐÎÆµÆ×ͼ');
xlabel('ƵÂÊ');ylabel('·ù¶È')£»
µ÷ÓóÌÐò1£º
function hd=ideal_bs(Wcl,Wch,m); alpha=(m-1)/2; n=[0:1:(m-1)]; m=n-alpha+eps;
hd=[sin(m*pi)+sin(Wcl*m)-sin(Wch*m)]./(pi*m)
µ÷ÓóÌÐò2£º
function[db,mag,pha,w]=freqz_m2(b,a) [H,w]=freqz(b,a,1000,'whole'); H=(H(1:1:501))'; w=(w(1:1:501))'; mag=abs(H);
db=20*log10((mag+eps)/max(mag)); pha=angle(H);
4.»ùÓÚÈý½Ç´°µÄFIRÊý×Ö¸ßͨÂ˲¨Æ÷Éè¼Æ ²ÎÊý£º