%有四种窗口类型供选择
b=1;
close all;
i=0;
while(b);
    temp=menu('选择窗函数长度N','N=10','N=15','N=20','N=25','N=30','N=33','N=35','N=40','N=45','N=50','N=55','N=60','N=64');
    menu1=[10,15,20,25,30,33,35,40,45,50,55,60,64];
    N=menu1(temp);
    temp=menu('选择逼近理想低通滤波器截止频率Wc','Wc=pi/4','Wc=pi/2','Wc=3*pi/4','Wc=pi','Wc=0.5','Wc=1.0','Wc=1.5','Wc=2.0','Wc=2.5','Wc=3.0');
    menu2=[pi/4,pi/2,3*pi/4,pi,0.5,1,1.5,2,2.5,3];
    w=menu2(temp);
    n=[0

N-1)];
    hd=ideal(w,N);  %得到理想低通滤波器
    k=menu('请选择窗口类型:','boxcar','hamming','hanning','blackman');
    if k==1
        B=boxcar(N);
        string=['Boxcar','N=',num2str(N)];
    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)'; %得到FIR数字滤波器
    [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,'-');
    xlabel('n');
    ylabel('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]);
    xlabel('w/pi');
    ylabel('dB');
    title('衰减特性(dB)');
    grid;
    subplot(2,2,3);
    plot(m,pha);
    hold on;
    n=0:7;
    x=zeros(8);
    plot(n,x,'-');
    title('相频特性');
    xlabel('频率(rad)');
    ylabel('相位(rad)');
    axis([0,3.15,-4,4]);
    subplot(2,2,4);
    plot(m,mag);
    title('频率特性');
    xlabel('频率W(rad)');
    ylabel('幅值');
    axis([0,3.15,0,1.5]);
    text(0.9,1.2,string);
    
    b=menu('Do You want To Continue ?','Yes','No');
    if b==2
        b=0;
    end
end
temp=menu('Close All Figure ?','Yes','No');
if temp==1
    close all
end