代码:

  1. %% ------------------------------------------------------------------------
  2. %% Output Info about this m-file
  3. fprintf('\n***********************************************************\n');
  4. fprintf(' <DSP using MATLAB> Problem 8.42 \n\n');
  5.  
  6. banner();
  7. %% ------------------------------------------------------------------------
  8.  
  9. % Digital Filter Specifications: Elliptic bandstop
  10. wsbs = [0.40*pi 0.48*pi]; % digital stopband freq in rad
  11. wpbs = [0.25*pi 0.75*pi]; % digital passband freq in rad
  12.  
  13. Rp = 1.0 % passband ripple in dB
  14. As = 80 % stopband attenuation in dB
  15.  
  16. Ripple = 10 ^ (-Rp/20) % passband ripple in absolute
  17. Attn = 10 ^ (-As/20) % stopband attenuation in absolute
  18.  
  19. % Calculation of Elliptic filter parameters:
  20.  
  21. [N, wn] = ellipord(wpbs/pi, wsbs/pi, Rp, As);
  22.  
  23. fprintf('\n ********* Elliptic Digital Bandstop Filter Order is = %3.0f \n', 2*N)
  24.  
  25. % Digital Elliptic bandstop Filter Design:
  26. [bbs, abs] = ellip(N, Rp, As, wn, 'stop');
  27.  
  28. [C, B, A] = dir2cas(bbs, abs)
  29.  
  30. % Calculation of Frequency Response:
  31. [dbbs, magbs, phabs, grdbs, wwbs] = freqz_m(bbs, abs);
  32.  
  33. % ---------------------------------------------------------------
  34. % find Actual Passband Ripple and Min Stopband attenuation
  35. % ---------------------------------------------------------------
  36. delta_w = 2*pi/1000;
  37. Rp_bs = -(min(dbbs(1:1:ceil(wpbs(1)/delta_w+1)))); % Actual Passband Ripple
  38.  
  39. fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp_bs);
  40.  
  41. As_bs = -round(max(dbbs(ceil(wsbs(1)/delta_w)+1:1:ceil(wsbs(2)/delta_w)+1))); % Min Stopband attenuation
  42. fprintf('\nMin Stopband attenuation is %.4f dB.\n\n', As_bs);
  43.  
  44. %% -----------------------------------------------------------------
  45. %% Plot
  46. %% -----------------------------------------------------------------
  47.  
  48. figure('NumberTitle', 'off', 'Name', 'Problem 8.42 Elliptic bs by ellip function')
  49. set(gcf,'Color','white');
  50. M = 1; % Omega max
  51.  
  52. subplot(2,2,1); plot(wwbs/pi, magbs); axis([0, M, 0, 1.2]); grid on;
  53. xlabel('Digital frequency in \pi units'); ylabel('|H|'); title('Magnitude Response');
  54. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.25, 0.40, 0.48, 0.75, M]);
  55. set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.01, 0.8913, 1]);
  56.  
  57. subplot(2,2,2); plot(wwbs/pi, dbbs); axis([0, M, -120, 2]); grid on;
  58. xlabel('Digital frequency in \pi units'); ylabel('Decibels'); title('Magnitude in dB');
  59. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.25, 0.40, 0.48, 0.75, M]);
  60. set(gca, 'YTickMode', 'manual', 'YTick', [ -80, -40, 0]);
  61. set(gca,'YTickLabelMode','manual','YTickLabel',['80'; '40';' 0']);
  62.  
  63. subplot(2,2,3); plot(wwbs/pi, phabs/pi); axis([0, M, -1.1, 1.1]); grid on;
  64. xlabel('Digital frequency in \pi nuits'); ylabel('radians in \pi units'); title('Phase Response');
  65. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.25, 0.40, 0.48, 0.75, M]);
  66. set(gca, 'YTickMode', 'manual', 'YTick', [-1:0.5:1]);
  67.  
  68. subplot(2,2,4); plot(wwbs/pi, grdbs); axis([0, M, 0, 50]); grid on;
  69. xlabel('Digital frequency in \pi units'); ylabel('Samples'); title('Group Delay');
  70. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.25, 0.40, 0.48, 0.75, M]);
  71. set(gca, 'YTickMode', 'manual', 'YTick', [0:20:50]);
  72.  
  73. % ------------------------------------------------------------
  74. % PART 2
  75. % ------------------------------------------------------------
  76.  
  77. % Discrete time signal
  78. Ts = 1; % sample intevals
  79. n1_start = 0; n1_end = 200;
  80. n1 = [n1_start:n1_end]; % [0:200]
  81.  
  82. xn1 = sin(0.44*pi*n1); % digital signal
  83.  
  84. % ----------------------------
  85. % DTFT of xn1
  86. % ----------------------------
  87. M = 500;
  88. [X1, w] = dtft1(xn1, n1, M);
  89.  
  90. %magX1 = abs(X1);
  91. angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1);
  92. magX1 = sqrt(realX1.^2 + imagX1.^2);
  93.  
  94. %% --------------------------------------------------------------------
  95. %% START X(w)'s mag ang real imag
  96. %% --------------------------------------------------------------------
  97. figure('NumberTitle', 'off', 'Name', 'Problem 8.42 X1 DTFT');
  98. set(gcf,'Color','white');
  99. subplot(2,1,1); plot(w/pi,magX1); grid on; %axis([-1,1,0,1.05]);
  100. title('Magnitude Response');
  101. xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
  102. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.2, 0.44, 0.6, 0.8, 1.0, 1.2, 1.4, 1.56, 1.8, 2]);
  103.  
  104. subplot(2,1,2); plot(w/pi, angX1/pi); grid on; %axis([-1,1,-1.05,1.05]);
  105. title('Phase Response');
  106. xlabel('digital frequency in \pi units'); ylabel('Radians/\pi');
  107.  
  108. figure('NumberTitle', 'off', 'Name', 'Problem 8.42 X1 DTFT');
  109. set(gcf,'Color','white');
  110. subplot(2,1,1); plot(w/pi, realX1); grid on;
  111. title('Real Part');
  112. xlabel('digital frequency in \pi units'); ylabel('Real');
  113. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.2, 0.44, 0.6, 0.8, 1.0, 1.2, 1.4, 1.56, 1.8, 2]);
  114.  
  115. subplot(2,1,2); plot(w/pi, imagX1); grid on;
  116. title('Imaginary Part');
  117. xlabel('digital frequency in \pi units'); ylabel('Imaginary');
  118. %% -------------------------------------------------------------------
  119. %% END X's mag ang real imag
  120. %% -------------------------------------------------------------------
  121.  
  122. % ------------------------------------------------------------
  123. % PART 3
  124. % ------------------------------------------------------------
  125. yn1 = filter(bbs, abs, xn1);
  126. n2 = n1;
  127.  
  128. % ----------------------------
  129. % DTFT of yn1
  130. % ----------------------------
  131. M = 500;
  132. [Y1, w] = dtft1(yn1, n2, M);
  133.  
  134. %magY1 = abs(Y1);
  135. angY1 = angle(Y1); realY1 = real(Y1); imagY1 = imag(Y1);
  136. magY1 = sqrt(realY1.^2 + imagY1.^2);
  137.  
  138. %% --------------------------------------------------------------------
  139. %% START Y1(w)'s mag ang real imag
  140. %% --------------------------------------------------------------------
  141. figure('NumberTitle', 'off', 'Name', 'Problem 8.42 Y1 DTFT');
  142. set(gcf,'Color','white');
  143. subplot(2,1,1); plot(w/pi,magY1); grid on; %axis([-1,1,0,1.05]);
  144. title('Magnitude Response');
  145. xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
  146. subplot(2,1,2); plot(w/pi, angY1/pi); grid on; %axis([-1,1,-1.05,1.05]);
  147. title('Phase Response');
  148. xlabel('digital frequency in \pi units'); ylabel('Radians/\pi');
  149.  
  150. figure('NumberTitle', 'off', 'Name', 'Problem 8.42 Y1 DTFT');
  151. set(gcf,'Color','white');
  152. subplot(2,1,1); plot(w/pi, realY1); grid on;
  153. title('Real Part');
  154. xlabel('digital frequency in \pi units'); ylabel('Real');
  155. subplot(2,1,2); plot(w/pi, imagY1); grid on;
  156. title('Imaginary Part');
  157. xlabel('digital frequency in \pi units'); ylabel('Imaginary');
  158. %% -------------------------------------------------------------------
  159. %% END Y1's mag ang real imag
  160. %% -------------------------------------------------------------------
  161.  
  162. figure('NumberTitle', 'off', 'Name', 'Problem 8.42 x(n) and y(n)')
  163. set(gcf,'Color','white');
  164. subplot(2,1,1); stem(n1, xn1);
  165. xlabel('n'); ylabel('x(n)');
  166. title('xn sequence'); grid on;
  167. subplot(2,1,2); stem(n1, yn1);
  168. xlabel('n'); ylabel('y(n)');
  169. title('yn sequence'); grid on;

  运行结果:

我自己假设通带1dB,阻带衰减80dB。

在此基础上设计指标,绝对单位,

ellip函数(MATLAB工具箱函数)得到Elliptic带阻滤波器,阶数为10,系统函数串联形式系数如下图。

Elliptic带阻滤波器,幅度谱、相位谱和群延迟响应

输入离散时间信号x(n)的谱如下,可看出,频率分量0.44π

通过带阻滤波器后,得到的输出y(n)的谱,好像变乱了,o(╥﹏╥)o

输入和输出的离散时间序列如下图

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

  1. 《DSP using MATLAB》Problem 7.14

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

  2. 《DSP using MATLAB》Problem 7.27

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

  3. 《DSP using MATLAB》Problem 7.26

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

  4. 《DSP using MATLAB》Problem 7.25

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

  5. 《DSP using MATLAB》Problem 7.24

    又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...

  6. 《DSP using MATLAB》Problem 7.23

    %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info a ...

  7. 《DSP using MATLAB》Problem 7.16

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

  8. 《DSP using MATLAB》Problem 7.15

    用Kaiser窗方法设计一个台阶状滤波器. 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  9. 《DSP using MATLAB》Problem 7.13

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

随机推荐

  1. mysql|tomcat|nginx|redis在docker中的部署

    MySQL部署 拉取MySQL镜像 docker pull mysql 查看镜像 创建MySQL容器 docker run -di --name pinyougou_mysql -p 33306:33 ...

  2. Ext 消息框

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. Linux网卡驱动(4)—DM9000网卡驱动程序完全分析

    1.硬件连接 mini2440开发板上DM9000的电气连接和mach-mini2440.c文件的关系 其中片选信号AEN使用了nGCS4,所以网卡的内存区域在BANK4,也就是从地址0x200000 ...

  4. XSS漏洞的渗透利用另类玩法

    XSS漏洞的渗透利用另类玩法 2017-08-08 18:20程序设计/微软/手机 作者:色豹 i春秋社区 今天就来讲一下大家都熟悉的 xss漏洞的渗透利用.相信大家对xss已经很熟悉了,但是很多安全 ...

  5. Python 中练习题涉及到的无穷大和无穷小问题。

    首先来看一下所见的python联系题. inf = infinite 无限制的 float("inf")-1执行后的结果是:() A 1 B inf C -inf D 0 该考点考 ...

  6. [转] Linux下编写脚本实现Daemon

    在Linux(以Redhat Linux Enterprise Edition 5.3为例)下,有时需要编写Service.Service也是程序,一般随系统启动用户不干预就不退出的程序,可以称为Se ...

  7. CH1201 最大子序和 (单调队列)

    题目链接: AcWing 牛客 题目描述 输入一个长度为n的整数序列,从中找出一段不超过m的连续子序列,使得整个序列的和最大. 例如 1,-3,5,1,-2,3 当m=4时,S=5+1-2+3=7 当 ...

  8. 自定义hive文件和记录格式及文本文件数据编码

    (1)一段 建表语句: [ROW FORMAT row_format] [STORED AS file_format] | STORED BY 'storage.handler.class.name' ...

  9. hdu6395 /// 优先队列dijkstra

    题目大意: 给定无向图的n m为点数和边数 接下来m行给定u v id表示点u到点v间有一条编号为id的边 当由一条边走到另一条边 而两条边的编号不同时 费用+1 优先队列跑dijkstra最短路 按 ...

  10. JavaScript中的面向对象编程,详解原型对象及prototype,constructor,proto,内含面向对象编程详细案例(烟花案例)

    面向对象编程:   面向:以什么为主,基于什么模式 对象:由键值对组成,可以用来描述事物,存储数据的一种数据格式 编程:使用代码解决需求   面向过程编程:         按照我们分析好的步骤,按步 ...