• 大小: 2KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-05-14
  • 语言: Matlab
  • 标签: FIR  MATLAB  

资源简介

自己写的线性相位的FIR低通和带通的数字滤波器程序,绝对没有错误,注释非常详细。用的是窗函数法,画了单位冲击响应和幅频响应的图。

资源截图

代码片段和文件信息

% 设计线性相位的FIR带通滤波器
% 2014.03.12 
clcclear all;
wls=0.2*pi;                            % 阻带最小频率 
wlp=0.35*pi;                           % 通带最小频率
whp=0.65*pi;                           % 通带最大频率
whs=0.8*pi;                            % 阻带最大频率 
wc=[wlp/piwhp/pi];                    % 带通滤波器的归一化截止频率
B=wlp-wls;                             % 过渡带宽=低端通带截止频率-低端阻带截止频率 
N=ceil(6.2*pi/B);                      % hanning窗阶数N,由过渡带宽B=8*pi/N算出Nceil为取整函数
window=hanning(N);                     % 窗选择hanning窗,为N*1的矩阵/向量
n=0:1:N-1; 
[h1w]=freqz(window1);                % window是N*1矩阵,h1是hannning窗的频率响应
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(221);                        % 将多个图画在一个平面上
stem(window);                          % 绘制离散序列图
axis([0 45 0 1.2]);                    % 定义xy轴范围 
grid;                                  % 显示网格线
xlabel(‘n‘);                           % x轴命名
title(‘Hanning窗函数‘);               
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(222);
plot(w/pi20*log(abs(h1)/abs(h1(1)))); % w来自freqz函数,为N个频率等分点的值(N*1矩阵),后面计算的是幅度值
axis([0 1 -350 0]);
grid;
xlabel(‘w/pi‘);
ylabel(‘幅度(dB)‘);
title(‘Hanning 窗函数的频谱‘);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hn=fir1(N-1wchanning(N));            % 设计filter。函数fir1返回的是filter的系数h(n)即冲激相应
[h2w]=freqz(hn1512);                % filter的频率响应h2
subplot(223);
stem(nhn);
axis([0 45 -0.25 0.25]);
grid;
xlabel(‘n‘);
ylabel(‘h(n)‘);
title(‘Hanning 窗函数的单位脉冲响应‘);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(224);
plot(w/pi20*log(abs(h2)/abs(h2(1))));  % w来自freqz(与h2对应)
grid;
xlabel(‘w/pi‘);
ylabel(‘幅度(dB)‘);
title(‘Hanning 窗设计带通滤波器的幅频响应‘);




 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2034  2014-03-13 21:33  FIR_BPF.m

     文件       1892  2014-03-13 21:34  FIR_LPF.m

----------- ---------  ---------- -----  ----

                 3926                    2


评论

共有 条评论