?? main.m
字號:
close all;
b=1;
while(b==1)
N=input('請輸入窗的長度N=:\n');
w1=input('請輸入上截止頻率W1(rad/pi):\n');
w2=input('請輸入下截止頻率W2(rad/pi):\n');
w1=w1*pi;
w2=w2*pi;
hd=ideal(w1,N)-ideal(w2,N);; %得到理想帶通濾波器
[B,n,string]=window(N); %選擇窗函數(shù)
h=hd.*B; %得到FIR數(shù)字濾波器
[H,m]=freqz(h,[1],1024,'whole'); %求其頻率響應(yīng)
mag=abs(H); %得到幅值
db=20*log10((mag+eps)/max(mag));
pha=angle(H); %得到相位
figure;
subplot(2,2,1);
stem(n,h,'.');
axis([0,N-1,-0.3,0.3]);
hold on;
x=zeros(N);
plot(n,x,'r-');
xlabel('n');
ylabel('h(n)');
title('實(shí)際低通濾波器的h(n)');
text((0.3*N),0.2,string);
hold off;
subplot(2,2,2);
plot(m/pi,db);
axis([0,1,-100,0]);
xlabel('w/pi');
ylabel('dB');
title('衰減特性(dB)');
set(gca,'ytick',[-60,-20,-3]);
grid;
subplot(2,2,3);
plot(m/pi,mag);
title('幅頻特性');
xlabel('w/pi');
ylabel('幅值');
axis([0,1,0,1.5]);
text(0.4,0.8,string);
subplot(2,2,4);
plot(m/pi,pha);
hold on;
n=0:7;
x=zeros(8);
plot(n,x,'r-');
title('相頻特性');
xlabel('w/pi');
ylabel('相位(rad)');
axis([0,1,-4,4]);
b=input('還要繼續(xù)嗎?:1(continue),0(exit):\n');
end
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -