⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 window.m

📁 用窗函数设计法设计fir滤波器(矩形窗、汉宁窗、汉明窗、布拉克曼窗、凯泽窗)
💻 M
字号:
function [x,n,string]=window(N)
n=0:N-1;
k=input('请选择窗的类型(1、矩形窗(boxcar) 2、汉宁窗(hanning) 3、汉明窗(hamming) 4、布拉克曼窗(blackman) 5、凯泽窗(Kaiser)(1,2,3,4,5):');
switch k
    case 1
        x=juxing(0,N-1,0,N-1);
        figure,subplot(2,1,1);stem(n,x,'.');xlabel('n');ylabel('x');string=['Boxcar时域图形','N=',num2str(N)];text((0.6*N),0.8,string);
        [H,m]=freqz(x,[1],1024,'whole'); %求其频率响应
        mag=abs(H); %得到幅值
        db=20*log10((mag+eps)/max(mag));
        subplot(2,1,2); plot(m/pi,db);xlabel('w/pi');ylabel('dB');title('矩形窗的幅度特性(db)');axis([0,1,-100,0]);
        string=['Boxcar','N=',num2str(N)];
    case 2
        x=juxing(0,N-1,0,N-1);
        x=(0.5-0.5*cos(2*pi*n/(N-1))).*x;
        figure,subplot(2,1,1);stem(n,x,'.');xlabel('n');ylabel('x');string=['Hanning时域图形','N=',num2str(N)];text((0.6*N),0.8,string);
       [H,m]=freqz(x,[1],1024,'whole'); %求其频率响应
        mag=abs(H); %得到幅值
        db=20*log10((mag+eps)/max(mag));
        subplot(2,1,2); plot(m/pi,db);xlabel('w/pi');ylabel('dB');title('汉宁窗的幅度特性(db)');axis([0,1,-100,0]);
        string=['Hanning','N=',num2str(N)];
    case 3
        x=juxing(0,N-1,0,N-1);
        x=(0.54-0.46*cos(2*pi*n/(N-1))).*x;
        figure,subplot(2,1,1);stem(n,x,'.');xlabel('n');ylabel('x');string=['Hamming时域图形','N=',num2str(N)];text((0.6*N),0.8,string);
       [H,m]=freqz(x,[1],1024,'whole'); %求其频率响应
        mag=abs(H); %得到幅值
        db=20*log10((mag+eps)/max(mag));
        subplot(2,1,2); plot(m/pi,db);xlabel('w/pi');ylabel('dB');title('汉明窗的幅度特性(db)');axis([0,1,-100,0]);
        string=['Hamming','N=',num2str(N)];
    case 4
        x=juxing(0,N-1,0,N-1);
        x=(0.42-0.5*cos(2*pi*n/(N-1))+0.08*cos(4*pi*n/(N-1))).*x;
        figure,subplot(2,1,1);stem(n,x,'.');xlabel('n');ylabel('x');string=['Blackman时域图形','N=',num2str(N)];text((0.6*N),0.8,string);
       [H,m]=freqz(x,[1],1024,'whole'); %求其频率响应
        mag=abs(H); %得到幅值
        db=20*log10((mag+eps)/max(mag));
        subplot(2,1,2); plot(m/pi,db);xlabel('w/pi');ylabel('dB');title('布拉克曼窗的幅度特性(db)');axis([0,1,-100,0]);
        string=['Blackman','N=',num2str(N)];
    otherwise
        x=juxing(0,N-1,0,N-1);
        a=input('请输入a(典型值为4<a<9)=');
        b=a*sqrt(1-(2*n/(N-1)-1).^2);
        x=(besseli(0,b)/besseli(0,a)).*x;
        figure,subplot(2,1,1);stem(n,x,'.');xlabel('n');ylabel('x');string=['Kaiser时域图形','N=',num2str(N)];text((0.6*N),0.8,string);
       [H,m]=freqz(x,[1],1024,'whole'); %求其频率响应
        mag=abs(H); %得到幅值
        db=20*log10((mag+eps)/max(mag));
        subplot(2,1,2); plot(m/pi,db);xlabel('w/pi');ylabel('dB');title('凯泽窗的幅度特性(db)');axis([0,1,-100,0]);
        string=['Kaiser','N=',num2str(N)];
end



        
        
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -