用Kaiser窗方法设计一个台阶状滤波器。

代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.15 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % staircase bandpass 3-Band
w1 = 0; w2 = 0.3*pi; delta1 = 0.01;
w3 = 0.4*pi; w4 = 0.7*pi; delta2 = 0.005;
w5 = 0.8*pi; w6 = pi; delta3 = 0.001; tr_width = min(w3-w2, w5-w3); f = [0 w2 w3 w4 w5 w6]/pi;
m = [1 1 0.5 0.5 0 0]; [Rp1, As1] = delta2db(delta1, delta3);
[Rp2, As2] = delta2db(delta2, delta3);
As = min(As1, As2) M = ceil((As-7.95)/(2.285*tr_width)) + 1; % Kaiser Window Length if As > 21 || As < 50
beta = 0.5842*(As-21)^0.4 + 0.07886*(As-21);
else
beta = 0.1102*(As-8.7);
end fprintf('\nKaiser Window method, Filter Length: M = %d. beta = %.4f\n', M, beta); n = [0:1:M-1]; wc1 = (w2+w3)/2; wc2 = (w4+w5)/2; %wc = (ws + wp)/2, % ideal LPF cutoff frequency hd = ideal_lp(wc1, M) + 0.5*(ideal_lp(wc2, M) - ideal_lp(wc1, M));
w_kai = (kaiser(M, beta))'; h = hd .* w_kai;
[db, mag, pha, grd, w] = freqz_m(h, [1]); delta_w = 2*pi/1000;
[Hr,ww,P,L] = ampl_res(h); Rp1 = -(min(db(1 :1: w2/delta_w+1))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple1 is %.4f dB.\n', Rp1); Rp2 = -(min(db(w3/delta_w+1 :1: w4/delta_w+1))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple2 is %.4f dB.\n', Rp2); As = -round(max(db(floor(w5/delta_w)+1 : 1 : floor(w6/delta_w)+1 ))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); [delta1, delta3] = db2delta(Rp1, As)
[delta2, delta3] = db2delta(Rp2, As) % Plot figure('NumberTitle', 'off', 'Name', 'Problem 7.15 ideal_lp Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.3 0.5]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n, w_kai); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Kaiser Window'); subplot(2,2,3); stem(n, h); axis([0 M-1 -0.3 0.5]); grid on;
xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response'); subplot(2,2,4); plot(w/pi, db); axis([0 1 -120 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-90,-65,-6,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'65';' 6';' 0']);
set(gca,'XTickMode','manual','XTick',[f]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); figure('NumberTitle', 'off', 'Name', 'Problem 7.15 h(n) ideal_lp Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -120 10]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-90,-65,-6,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'65';' 6';' 0']);
set(gca,'XTickMode','manual','XTick',[f,1+f(2:6)]); subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 2 -100 10]);
xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
set(gca,'XTickMode','manual','XTick',[f,1+f(2:6)]);
set(gca,'YTickMode','manual','YTick',[0,0.5, 1]) subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay'); figure('NumberTitle', 'off', 'Name', 'Problem 7.15 Amp Res of h(n)')
set(gcf,'Color','white'); plot(ww/pi, Hr); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Hr'); title('Amplitude Response');
set(gca,'YTickMode','manual','YTick',[-delta3,0,delta3,0.5-0.005, 0.5+0.005,1-delta1,1,1+delta1])
%set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
set(gca,'XTickMode','manual','XTick',[f,2]); %% +++++++++++++++++++++++++++++++++++++++++++++++++
%% fir2 function method
%% +++++++++++++++++++++++++++++++++++++++++++++++++
f = [w1, w2, w3, w4, w5, w6]/pi;
m = [1 1 0.5 0.5 0 0];
ripple = [0.01 0.005 0.001]; fprintf('\n--------- use fir2 function ---------\n'); h_check = fir2(M-1, f, m, kaiser(M, beta)); [db, mag, pha, grd, w] = freqz_m(h_check, [1]);
%[Hr,ww,P,L] = ampl_res(h_check);
[Hr,ww,P,L] = Hr_Type2(h_check); %% -------------------------------------------
%% plot
%% -------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 7.15 fir2 Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.3 0.5]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n, w_kai); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Kaiser Window'); subplot(2,2,3); stem([0:M-1], h_check); axis([0 M -0.3 0.5]); grid on;
set(gca,'XTickMode','manual','XTick',[0 M/2 M]);
xlabel('n'); ylabel('h\_check(n)'); title('Actual Impulse Response'); subplot(2,2,4); plot(w/pi, db); axis([0 1 -120 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-90,-65,-6,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'65';' 6';' 0']);
set(gca,'XTickMode','manual','XTick',[f]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); figure('NumberTitle', 'off', 'Name', 'Problem 7.15 h_check(n) fir2 Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -120 10]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-90,-65,-6,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'65';' 6';' 0']);
set(gca,'XTickMode','manual','XTick',[f,1+f(2:6)]); subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 2 -100 10]);
xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
set(gca,'XTickMode','manual','XTick',[f,1+f(2:6)]);
set(gca,'YTickMode','manual','YTick',[0,0.5, 1]) subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay');

  运行结果:

Kaiser窗长M=74,两个通带衰减分别为0.0079dB和6.0345dB,阻带最小衰减65dB>60dB,满足设计要求。

用理想低通滤波方法设计的结果,实际脉冲响应、幅度谱(dB单位)

幅度谱(dB和绝对单位)、相位谱和群延迟响应

振幅响应(台阶状)

第一个台阶(通带)

第二个台阶(通带)

阻带

题目中暗示可以用fir1函数,但查了帮助和网上资料还是不会,只好用fir2函数的方法来设计,结果如下:

群延迟不是严格的常数了,非线性相位滤波器。

《DSP using MATLAB》Problem 7.15的更多相关文章

  1. 《DSP using MATLAB》Problem 6.15

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  2. 《DSP using MATLAB》Problem 5.15

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  3. 《DSP using MATLAB》Problem 4.15

    只会做前两个, 代码: %% ---------------------------------------------------------------------------- %% Outpu ...

  4. 《DSP using MATLAB》Problem 2.15

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  5. 《DSP using MATLAB》Problem 8.15

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  6. 《DSP using MATLAB》Problem 5.38

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...

  7. 《DSP using MATLAB》Problem 5.31

    第3小题: 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Out ...

  8. 《DSP using MATLAB》Problem 5.22

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% O ...

  9. 《DSP using MATLAB》Problem 5.21

    证明: 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

随机推荐

  1. MAVEN项目环境搭建

    一.Maven的环境配置 apache-maven-3.5.4 Maven下载地址:http://maven.apache.org/download.cgi 选择下载  直接解压无需安装()下面配置M ...

  2. MySQL索引的原理,B+树、聚集索引和二级索引的结构分析

    索引是一种用于快速查询行的数据结构,就像一本书的目录就是一个索引,如果想在一本书中找到某个主题,一般会先找到对应页码.在mysql中,存储引擎用类似的方法使用索引,先在索引中找到对应值,然后根据匹配的 ...

  3. spark中map与mapPartitions区别

    在spark中,map与mapPartitions两个函数都是比较常用,这里使用代码来解释一下两者区别 import org.apache.spark.{SparkConf, SparkContext ...

  4. erlang并发编程

    1.erlang中创建进程(非操作系统线程,比其要轻量很多)非常方便,运用spawn函数即可 spawn(Fun) -> pid() spawn(Node, Fun) -> pid() s ...

  5. 模块化 Sea.js(CMD)规范 RequireJS(AMD)规范 的用法

    插入第三方库AMD CMD都 一样  如:JQ(再JQ源码里修改) 使用seajs的步骤 1.HTML里引入seajs <script src="./lib/sea.js"& ...

  6. Problem C: 平面上的点和线——Point类、Line类 (III)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定,两点确定一条线段.现在我们封装一个“Point类”和“Line类”来实现平面上的点的操作. 根据“append ...

  7. Burpsuite安全测试测试指导

    1    Burpsuite简介 Burpsuite是一款安全领域非常重要的Web扫描工具(或者说是平台),它用于攻击Web应用程序.在Burp Suite上集成了各种扫描工具插件,各个集成插件可以组 ...

  8. 移动端click事件无反应或反应慢 touchend事件页面滑动时频繁触发

    H5页面的点击事件click 无论在浏览器 iframe还是小程序里面 都会出现点击无反应或者反应慢的情况出现 所以决定用touchend事件来代替click 但是touchend事件触发比较灵敏 在 ...

  9. mysql5.5.25 中文问题 my.ini没有及配置问题 修改默认编码方式

    1.当你向mysql输入中文后,用select查询结果中文变成了问号,那你就往下看. 2.打开cmd,进入mysql,输入show variables like"%char%";可 ...

  10. 读取HeidiSQL 配置文件中的密码

    读取HeidiSQL 配置文件中的密码 2017-1-21 5:42:01 codegay HeidiSQL是一款开源的SQL管理工具,用管理MYSQL,MSSQL 等数据库, 很多管理工具都会把密码 ...