代码:

  1. %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. %% Output Info about this m-file
  3. fprintf('\n***********************************************************\n');
  4. fprintf(' <DSP using MATLAB> Problem 7.10 \n\n');
  5.  
  6. banner();
  7. %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8.  
  9. wp1 = 0.3*pi; ws1 = 0.4*pi; ws2 = 0.6*pi; wp2 = 0.7*pi;
  10. As = 50; Rp = 0.2;
  11. tr_width = min( ws1-wp1, wp2-ws2 );
  12. M = ceil(6.6*pi/tr_width) + 1; % Hamming Window
  13. fprintf('\nFilter Length is %d.\n', M);
  14.  
  15. n = [0:1:M-1]; wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2;
  16.  
  17. %wc = (ws + wp)/2, % ideal LPF cutoff frequency
  18.  
  19. hd = ideal_lp(wc1, M) + ideal_lp(pi, M) - ideal_lp(wc2, M);
  20. w_ham = (hamming(M))'; h = hd .* w_ham;
  21. [db, mag, pha, grd, w] = freqz_m(h, [1]); delta_w = 2*pi/1000;
  22. [Hr,ww,P,L] = ampl_res(h);
  23.  
  24. Rp = -(min(db(1 : 1 : wp1/delta_w+1))); % Actual Passband Ripple
  25. fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp);
  26.  
  27. As = -round(max(db(ws1/delta_w+1 : 1 : ws2/delta_w))); % Min Stopband attenuation
  28. fprintf('\nMin Stopband attenuation is %.4f dB.\n', As);
  29.  
  30. [delta1, delta2] = db2delta(Rp, As)
  31.  
  32. %Plot
  33.  
  34. figure('NumberTitle', 'off', 'Name', 'Problem 7.10 ideal_lp Method')
  35. set(gcf,'Color','white');
  36.  
  37. subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.2 0.8]); grid on;
  38. xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response');
  39. subplot(2,2,2); stem(n, w_ham); axis([0 M-1 0 1.1]); grid on;
  40. xlabel('n'); ylabel('w(n)'); title('Hamming Window');
  41. subplot(2,2,3); stem(n, h); axis([0 M-1 -0.2 0.8]); grid on;
  42. xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response');
  43.  
  44. subplot(2,2,4); plot(w/pi, db); axis([0 1 -120 10]); grid on;
  45. set(gca,'YTickMode','manual','YTick',[-90,-50,0]);
  46. set(gca,'YTickLabelMode','manual','YTickLabel',['90';'50';' 0']);
  47. set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.6,0.7,1]);
  48. xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
  49.  
  50. figure('NumberTitle', 'off', 'Name', 'Problem 7.10 h(n) ideal_lp Method')
  51. set(gcf,'Color','white');
  52.  
  53. subplot(2,2,1); plot(w/pi, db); grid on; axis([0 1 -120 10]);
  54. set(gca,'YTickMode','manual','YTick',[-90,-50,0])
  55. set(gca,'YTickLabelMode','manual','YTickLabel',['90';'50';' 0']);
  56. set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.6,0.7,1]);
  57. xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
  58.  
  59. subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 1 -100 10]);
  60. xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
  61. set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.6,0.7,1,1.3,1.4,1.6,1.7,2]);
  62. set(gca,'YTickMode','manual','YTick',[0,1.0]);
  63.  
  64. subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
  65. xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
  66. subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
  67. xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay');
  68.  
  69. figure('NumberTitle', 'off', 'Name', 'Problem 7.10 h(n)')
  70. set(gcf,'Color','white');
  71.  
  72. plot(ww/pi, Hr); grid on; %axis([0 1 -100 10]);
  73. xlabel('frequency in \pi units'); ylabel('Hr'); title('Amplitude Response');
  74. set(gca,'YTickMode','manual','YTick',[-0.0032, 0,0.0032, 0.9975, 1,1.0025]);
  75. %set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
  76. %set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.55,0.75,1,1.2,1.35,1.55,1.75,2]);

  运行结果:

阻带最小衰减为50dB,满足设计要求。

用Hamming窗设计的滤波器脉冲响应,其幅度响应(dB和Absolute单位)、相位响应和群延迟响应。

振幅响应(Absolute单位)

通带部分

阻带部分

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

  1. 《DSP using MATLAB》Problem 6.10

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

  2. 《DSP using MATLAB》Problem 5.10

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

  3. 《DSP using MATLAB》Problem 4.10

    今天擦完了玻璃,尽管有地方不那么明亮干净,冷风中瑟瑟发抖,年也快临近了. 代码是从网上找的, function [p, np, r, nr] = deconv_m(b, nb, a, na) % Mo ...

  4. 《DSP using MATLAB》Problem 3.10

    用到了三角窗脉冲序列,各小题的DTFT就不写公式了,直接画图(这里只贴长度M=10的情况). 1. 代码: %% ------------------------------------------- ...

  5. 《DSP using MATLAB》Problem 2.10

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

  6. 《DSP using MATLAB》Problem 8.10

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

  7. 《DSP using MATLAB》Problem 7.27

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

  8. 《DSP using MATLAB》Problem 7.26

    注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...

  9. 《DSP using MATLAB》Problem 7.25

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

随机推荐

  1. IDEA中静态资源无法找到的原因

    IDEA中静态资源无法找到, 原因1:同名的文件但是在不同的包里. 原因2:IDEA重启,web清空缓存. 原因3:错误的文件及路径. 原因4:其他原因排除后,可使用绝招重启试试.

  2. webpack4入门

    前提 已安装node(版本号>4.0,已自带NPM) mac机器 有一个空目录 无webpack.config.js配置打包 快速构建package.json文件. npm init -y 安装 ...

  3. centos7中安装python3.7遇到的问题

    安装python3.7的步骤 wget   https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz yum install -y gcc ...

  4. EPEL源-是什么全称

    EPEL源   EPEL (Extra Packages for Enterprise Linux)是基于Fedora的一个项目,为“红帽系”的操作系统提供额外的软件包,适用于RHEL.CentOS和 ...

  5. nginx windows版 下载和启动

    nginx Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.因它的稳定性.丰富的功能集.示例配置文件和低系统资源的消耗而闻名.在连 ...

  6. Qgis练手

    师妹推荐了一个神器 Qgis,因为看我拿Echarts和Excel缝缝补补效率实在太低下. 还记得,以前写过一个“echarts画中国地图并上色”的笔记,那个应付一下事还行,真正需要精细画图的时候还得 ...

  7. guxh的python笔记十:包和模块

    1,包和模块 包package:本质就是一个文件夹/目录,必须带一个__init.__.py的文件 模块module:.py结尾的python文件 2,导入方法 import pandas, coll ...

  8. 【警告】WARN: Establishing SSL connection without server's identity verification is not recommended.

    1.Java访问Mysql时出现如下警告: 2019-04-02 10:30:50.545 INFO 1290 --- [nio-8080-exec-1] com.zaxxer.hikari.Hika ...

  9. 实现android"转盘抽奖"小项目后感想

    我这次做的小项目是android的转盘抽奖,因为这个小项目中有进程的调度,加锁等细节,而我们组的竞赛系统中也有这样的问题.通过这次的实践我发现了自己的好多问题也学到了很多. 个人问题: 1.自己的动手 ...

  10. js中的object

    JavaScript is an object-based language based on prototypes, rather than being class-based. this引用对象 ...