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

代码:

  1. %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. %% Output Info about this m-file
  3. fprintf('\n***********************************************************\n');
  4. fprintf(' <DSP using MATLAB> Problem 7.26 \n\n');
  5.  
  6. banner();
  7. %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8.  
  9. % highpass, Only Type-1 filter
  10. ws1 = 0.4*pi; wp1 = 0.6*pi; As = 50; Rp = 0.004;
  11. tr_width = (wp1-ws1);
  12.  
  13. T2 = 0.5925; T1=0.1099;
  14. M = 31; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
  15. n = [0:1:M-1]; wc1 = (ws1+wp1)/2;
  16.  
  17. Hrs = [zeros(1,7),T1,T2,ones(1,14),T2,T1,zeros(1,6)]; % Ideal Amp Res sampled
  18. Hdr = [0, 0, 1, 1]; wdl = [0, 0.4, 0.6, 1]; % Ideal Amp Res for plotting
  19. k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
  20.  
  21. %% --------------------------------------------------
  22. %% Type-1 BPF
  23. %% --------------------------------------------------
  24. angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
  25. H = Hrs.*exp(j*angH); h = real(ifft(H, M));
  26.  
  27. [db, mag, pha, grd, w] = freqz_m(h, [1]); delta_w = 2*pi/1000;
  28. %[Hr,ww,P,L] = ampl_res(h);
  29. [Hr, ww, a, L] = Hr_Type1(h);
  30.  
  31. Rp = -(min(db(floor(wp1/delta_w)+1 :1: 501))); % Actual Passband Ripple
  32. fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp);
  33.  
  34. As = -round(max(db(1:1:floor(0.4*pi/delta_w)+1))); % Min Stopband attenuation
  35. fprintf('\nMin Stopband attenuation is %.4f dB.\n', As);
  36.  
  37. [delta1, delta2] = db2delta(Rp, As)
  38.  
  39. % Plot
  40.  
  41. figure('NumberTitle', 'off', 'Name', 'Problem 7.26a FreSamp Method')
  42. set(gcf,'Color','white');
  43. subplot(2,2,1); plot(wl(1:16)/pi, Hrs(1:16), 'o', wdl, Hdr, 'r'); axis([0, 1, -0.1, 1.1]);
  44. set(gca,'YTickMode','manual','YTick',[0,0.5,1]);
  45. set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);
  46. xlabel('frequency in \pi nuits'); ylabel('Hr(k)'); title('Frequency Samples: M=31,T1=0.5925,T2=0.1099');
  47. grid on;
  48.  
  49. subplot(2,2,2); stem(l, h); axis([-1, M, -0.4, 0.6]); grid on;
  50. xlabel('n'); ylabel('h(n)'); title('Impulse Response');
  51.  
  52. subplot(2,2,3); plot(ww/pi, Hr, 'r', wl(1:16)/pi, Hrs(1:16), 'o'); axis([0, 1, -0.2, 1.2]); grid on;
  53. xlabel('frequency in \pi units'); ylabel('Hr(w)'); title('Amplitude Response');
  54. set(gca,'YTickMode','manual','YTick',[0,0.5,1]);
  55. set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);
  56.  
  57. subplot(2,2,4); plot(w/pi, db); axis([0, 1, -100, 10]); grid on;
  58. xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response');
  59. set(gca,'YTickMode','manual','YTick',[-90,-60,-51,0]);
  60. set(gca,'YTickLabelMode','manual','YTickLabel',['90';'60';'51';' 0']);
  61. set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);
  62.  
  63. figure('NumberTitle', 'off', 'Name', 'Problem 7.26 h(n) FreSamp Method')
  64. set(gcf,'Color','white');
  65.  
  66. subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -120 10]);
  67. set(gca,'YTickMode','manual','YTick',[-90,-60,-51,0])
  68. set(gca,'YTickLabelMode','manual','YTickLabel',['90';'60';'51';' 0']);
  69. set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,2]);
  70. xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
  71.  
  72. subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 1 -100 10]);
  73. xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
  74. set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,2]);
  75. set(gca,'YTickMode','manual','YTick',[0,1.0]);
  76.  
  77. subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
  78. xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
  79. subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
  80. xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay');
  81.  
  82. figure('NumberTitle', 'off', 'Name', 'Problem 7.26 AmpRes of h(n), FreSamp Method')
  83. set(gcf,'Color','white');
  84.  
  85. plot(ww/pi, Hr); grid on; %axis([0 1 -100 10]);
  86. xlabel('frequency in \pi units'); ylabel('Hr'); title('Amplitude Response');
  87. set(gca,'YTickMode','manual','YTick',[-delta2, 0,delta2, 1-0.0258, 1,1+0.0258]);
  88. %set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
  89. set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);
  90.  
  91. %% ------------------------------------
  92. %% fir2 Method
  93. %% ------------------------------------
  94. f = [0 ws1 wp1 pi]/pi;
  95. m = [0 0 1 1 ];
  96. h_check = fir2(M+1, f, m); % if M is odd, then M+1; order
  97. [db, mag, pha, grd, w] = freqz_m(h_check, [1]);
  98. %[Hr,ww,P,L] = ampl_res(h_check);
  99. [Hr, ww, a, L] = Hr_Type1(h_check);
  100.  
  101. fprintf('\n----------------------------------\n');
  102. fprintf('\n fir2 function Method \n');
  103. fprintf('\n----------------------------------\n');
  104.  
  105. Rp = -(min(db(floor(wp1/delta_w)+1 :1: 501))); % Actual Passband Ripple
  106. fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp);
  107. As = -round(max(db(1:1:floor(0.4*pi/delta_w)+1 ))); % Min Stopband attenuation
  108. fprintf('\nMin Stopband attenuation is %.4f dB.\n', As);
  109.  
  110. [delta1, delta2] = db2delta(Rp, As)
  111.  
  112. figure('NumberTitle', 'off', 'Name', 'Problem 7.26 fir2 Method')
  113. set(gcf,'Color','white');
  114.  
  115. subplot(2,2,1); stem(n, h); axis([0 M-1 -0.4 0.6]); grid on;
  116. xlabel('n'); ylabel('h(n)'); title('Impulse Response');
  117.  
  118. %subplot(2,2,2); stem(n, w_ham); axis([0 M-1 0 1.1]); grid on;
  119. %xlabel('n'); ylabel('w(n)'); title('Hamming Window');
  120.  
  121. subplot(2,2,3); stem([0:M+1], h_check); axis([0 M+1 -0.4 0.6]); grid on;
  122. xlabel('n'); ylabel('h\_check(n)'); title('Actual Impulse Response');
  123.  
  124. subplot(2,2,4); plot(w/pi, db); axis([0 1 -120 10]); grid on;
  125. set(gca,'YTickMode','manual','YTick',[-90,-67,-21,0])
  126. set(gca,'YTickLabelMode','manual','YTickLabel',['90';'67';'21';' 0']);
  127. set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);
  128. xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
  129.  
  130. figure('NumberTitle', 'off', 'Name', 'Problem 7.26 h(n) fir2 Method')
  131. set(gcf,'Color','white');
  132.  
  133. subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -120 10]);
  134. xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
  135. set(gca,'YTickMode','manual','YTick',[-90,-67,-21,0]);
  136. set(gca,'YTickLabelMode','manual','YTickLabel',['90';'67';'21';' 0']);
  137. set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,2]);
  138.  
  139. subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 1 -100 10]);
  140. xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
  141. set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,2]);
  142. set(gca,'YTickMode','manual','YTick',[0,1.0]);
  143.  
  144. subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
  145. xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
  146. subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
  147. xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay');
  148.  
  149. figure('NumberTitle', 'off', 'Name', 'Problem 7.26 AmpRes of h(n),fir2 Method')
  150. set(gcf,'Color','white');
  151.  
  152. plot(ww/pi, Hr); grid on; %axis([0 1 -100 10]);
  153. xlabel('frequency in \pi units'); ylabel('Hr'); title('Amplitude Response');
  154. set(gca,'YTickMode','manual','YTick',[-0.08, 0,0.08, 1-0.04, 1,1+0.04]);
  155. %set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
  156. set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);

  运行结果:

振幅响应

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

  1. 《DSP using MATLAB》Problem 8.26

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

  2. 《DSP using MATLAB》Problem 4.26

    Y(z)部分分式展开, 零状态响应和零输入响应的部分分式展开,

  3. 《DSP using MATLAB》Problem 5.24-5.25-5.26

    代码: function y = circonvt(x1,x2,N) %% N-point Circular convolution between x1 and x2: (time domain) ...

  4. 《DSP using MATLAB》Problem 7.16

    使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  5. 《DSP using MATLAB》Problem 6.8

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

  6. 《DSP using MATLAB》Problem 2.16

    先由脉冲响应序列h(n)得到差分方程系数,过程如下: 代码: %% ------------------------------------------------------------------ ...

  7. 《DSP using MATLAB》Problem 7.32

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

  8. 《DSP using MATLAB》Problem 7.30

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

  9. 《DSP using MATLAB》Problem 7.27

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

随机推荐

  1. 关于angular 的路由title设置

    在主模块下 constructor( private router: Router, private activatedRoute: ActivatedRoute, ) {} this.router. ...

  2. python 统计单词个数,并按个数与字母排序

    # coding: utf-8 # In[1]: import collections str = "Be slow to promise and quick to perform" ...

  3. js 两数的最大公约数

    function gcd(a,b){ if (b == 0){ return a; } var r = parseInt(a % b) ; return gcd(b, r);}gcd(12,5);

  4. [Linux] Extend space of root disk in Linux7

    [root@node1 ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/centos-root 26G 17G 9.8G ...

  5. coreData的ManagedObject后,报错

    设置:Data Model inspector -> Codegen -> Manual/None (如下图右侧)↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ ...

  6. 转 Redis 总结精讲 看一篇成高手系统-4

    转 Redis 总结精讲 看一篇成高手系统-4 2018年05月31日 09:00:05 hjm4702192 阅读数:125633   本文围绕以下几点进行阐述 1.为什么使用redis 2.使用r ...

  7. ios ionic3 跳转第三方地图 xcode加入白名单

    之前我有篇随笔讲的是ionic3应用内跳转第三方地图应用的方法 忘了记录在ios内是需要把你用到的第三方地图应用加入跳转URL白名单内的 第三个是高德地图 iosamap 第四个是百度地图 baidu ...

  8. javap反汇编的使用

    javap可以查看class文件信息,灵活的运用javap,让你更好的理解class类文件结构信息等   方法/步骤     javap -help查看命令帮助   javap -package Te ...

  9. 安装linux虚拟机配置静态ip(NAT模式)

    1.centOs7.VMware Workstation14 2.常规配置硬件和基本信息后,在图形安装界面将以太网链接打开,安装后配置ifcfg-e****,这里是我的配置文件 修改BOOTPROTO ...

  10. Labview多列列表框

    前面板创建多列列表框 如何写入数据: 右键  创建属性节点  项名  创建属性节点  项符号 创造自定义项符号:  右键 创建调用节点  自定义项符号 设置为自定义符号 然后添加索引号 利用图片与声音 ...