📄 fir.m
字号:
N=yesinput('input the length of the windows N=:\n',15,[10,64]);
w=yesinput('Input The Wc:\n',pi/4,[0.5,pi]);
b=1;
close all;
i=0;
while(b);
n=[0:(N-1)];
hd=ideal(w,N);
k=yesinput('请选择窗口类型:1(boxcar)2(hamming)3(hanning)4(blackman):\n','1','1|2|3|4');
k=str2num(k);
if k==1
B=boxcar(N);
string=['Boxcar','N=',num2str(N)];7
else if k==2
B=hamming(N);
string=['Hamming','N=',num2str(N)];
else if k==3
B=hanning(N);
string=['Hanning','N=',num2str(N)];
else if k==4
B=blackman(N);
string=['Blackman','N=',num2str(N)];
end
end
end
end
h=hd.*(B)';
[H,m]=freqz(h,[1],1024,'whole');
mag=abs(H);
db=20*log10((mag+eps)/max(mag));
pha=angle(H);
i=i+1;
figure(i)
subplot(2,2,1);
n=0:N-1;
stem(n,h,'.');
axis([0 N-1 -0.1 0.3]);
hold on;
n=0:N-1;
x=zeros(N);
plot(n,x,'-');
xlable('n');
ylable('h(n)');
title('实际低通滤波器的h(n)');
text((0.3*N),0.27,string);
hold off;
subplot(2,2,2);
plot(m/pi,db);
axis([0 1 -100 0]);
xlable('w/pi');
ylable('dB');
title('衰减特性(dB)');
grid;
subplot(2,2,3);
plot(m,pha);
hold on;
n=0:7;
x=zeros(8);
plot(n,x,'-');
title('相频特性');
xlable('频率(rad)');
ylable('相位(rad)');
axis([0 3.15 -4 4]);
subplot(2,2,4);
plot(m,mag);
title('幅频特性');
xlable('频率W(rad)');
ylable('幅值');
axis([0 3.15 0 1.5]);
text(0.9,1.2,string);
b=yesinput('Do You want To Continue:1(Continue),0(Exit):\n',
1,[0 1]);
if (b==1)
N=yesinput('Input The length of the windows:\n',15,[10 50]);
w=yesinput('Input The Wc:\n',pi/4,[0.5,pi]);
end
end
% 子程序:产生理想低通滤波器单位脉冲响应hd(n)
function hd=ideal(w,N);
alpha=(N-1)/2;
n=[0:(N-1)];
m=n-alpha+eps;
hd=sin(w*m)./(pi*m);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -