代码:

  1. %% ------------------------------------------------------------------------
  2. %% Output Info about this m-file
  3. fprintf('\n***********************************************************\n');
  4. fprintf(' <DSP using MATLAB> Problem 3.18 \n\n');
  5.  
  6. banner();
  7. %% ------------------------------------------------------------------------
  8.  
  9. %% -------------------------------------------------------------------
  10. %% y(n)=x(n)+x(n-2)+x(n-4)+x(n-6)
  11. %% -0.81y(n-2)-0.81*0.81y(n-4)-0.81^3*y(n-6)
  12. %% -------------------------------------------------------------------
  13. a = [1, 0, 0.81, 0, 0.81^2, 0, 0.81^3]; % filter coefficient array a
  14. b = [1, 0, 1, 0, 1, 0, 1]; % filter coefficient array b
  15.  
  16. MM = 500;
  17.  
  18. [H, w] = freqresp1(b, a, MM);
  19.  
  20. magH = abs(H); angH = angle(H); realH = real(H); imagH = imag(H);
  21.  
  22. %% --------------------------------------------------------------------
  23. %% START H's mag ang real imag
  24. %% --------------------------------------------------------------------
  25. figure('NumberTitle', 'off', 'Name', 'Problem 3.18 H1');
  26. set(gcf,'Color','white');
  27. subplot(2,1,1); plot(w/pi,magH); grid on; %axis([-1,1,0,1.05]);
  28. title('Magnitude Response');
  29. xlabel('frequency in \pi units'); ylabel('Magnitude |H|');
  30. subplot(2,1,2); plot(w/pi, angH/pi); grid on; axis([-1,1,-1.05,1.05]);
  31. title('Phase Response');
  32. xlabel('frequency in \pi units'); ylabel('Radians/\pi');
  33.  
  34. figure('NumberTitle', 'off', 'Name', 'Problem 3.18 H1');
  35. set(gcf,'Color','white');
  36. subplot(2,1,1); plot(w/pi, realH); grid on;
  37. title('Real Part');
  38. xlabel('frequency in \pi units'); ylabel('Real');
  39. subplot(2,1,2); plot(w/pi, imagH); grid on;
  40. title('Imaginary Part');
  41. xlabel('frequency in \pi units'); ylabel('Imaginary');
  42. %% -------------------------------------------------------------------
  43. %% END X's mag ang real imag
  44. %% -------------------------------------------------------------------
  45.  
  46. %% --------------------------------------------------
  47. %% x1(n)=5+10*(-1)^n
  48. %% --------------------------------------------------
  49. M = 200;
  50. n1 = [0:M];
  51. x1 = 5 + 10*(-1).^n1;
  52.  
  53. y1 = filter(b, a, x1);
  54.  
  55. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.1 M = %d',M));
  56. set(gcf,'Color','white');
  57. subplot(2,1,1);
  58. stem(n1, x1);
  59. xlabel('n'); ylabel('x1');
  60. title(sprintf('x1(n) input sequence, M = %d', M)); grid on;
  61. subplot(2,1,2);
  62. stem(n1, y1);
  63. xlabel('n'); ylabel('y1');
  64. title(sprintf('y1(n) output sequence, M = %d', M)); grid on;
  65.  
  66. %% --------------------------------------------------
  67. %% x2(n)=1+cos(0.5pin+pi/2)
  68. %% --------------------------------------------------
  69.  
  70. n2 = n1;
  71. x2 = 1 + cos(0.5*pi*n2+pi/2);
  72.  
  73. y2 = filter(b, a, x2);
  74.  
  75. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.2 M = %d',M));
  76. set(gcf,'Color','white');
  77. subplot(2,1,1);
  78. stem(n2, x2);
  79. xlabel('n'); ylabel('x');
  80. title(sprintf('x2(n) input sequence, M = %d', M)); grid on;
  81. subplot(2,1,2);
  82. stem(n2, y2);
  83. xlabel('n'); ylabel('y');
  84. title(sprintf('y2(n) output sequence, M = %d', M)); grid on;
  85.  
  86. %% --------------------------------------------------
  87. %% x3(n)=2sin(pin/4) + 3cos(3pin/4)
  88. %% --------------------------------------------------
  89.  
  90. n3 = n1;
  91. x3 = 2*sin(pi*n3/4) + 3*cos(3*pi*n3/2);
  92.  
  93. y3 = filter(b, a, x3);
  94.  
  95. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.3 M = %d',M));
  96. set(gcf,'Color','white');
  97. subplot(2,1,1);
  98. stem(n3, x3);
  99. xlabel('n'); ylabel('x');
  100. title(sprintf('x3(n) input sequence, M = %d', M)); grid on;
  101. subplot(2,1,2);
  102. stem(n3, y3);
  103. xlabel('n'); ylabel('y');
  104. title(sprintf('y3(n) output sequence, M = %d', M)); grid on;
  105.  
  106. %% ------------------------------------------------------------------------------
  107. %% x4(n)=1+2cos(pin/4)+3cos(2pin/4)+4cos(3pin/4)+5cos(4pin/4)+6cos(5pin/4)
  108. %% ------------------------------------------------------------------------------
  109.  
  110. n4 = n1;
  111. sum = 0;
  112. for i = 0:5
  113. sum = sum + (i+1)*cos(i*pi*n4/4);
  114. end
  115. x4 = sum;
  116.  
  117. y4 = filter(b, a, x4);
  118.  
  119. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.4 M = %d',M));
  120. set(gcf,'Color','white');
  121. subplot(2,1,1);
  122. stem(n4, x4);
  123. xlabel('n'); ylabel('x');
  124. title(sprintf('x4(n) input sequence, M = %d', M)); grid on;
  125. subplot(2,1,2);
  126. stem(n4, y4);
  127. xlabel('n'); ylabel('y');
  128. title(sprintf('y4(n) output sequence, M = %d', M)); grid on;
  129.  
  130. %% -----------------------------------------------------------------
  131. %% x5(n)=cos(pin)
  132. %% -----------------------------------------------------------------
  133.  
  134. n5 = n1;
  135.  
  136. x5 = cos(pi*n5);
  137.  
  138. y5 = filter(b, a, x5);
  139.  
  140. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.5 M = %d',M));
  141. set(gcf,'Color','white');
  142. subplot(2,1,1);
  143. stem(n5, x5);
  144. xlabel('n'); ylabel('x');
  145. title(sprintf('x5(n) input sequence, M = %d', M)); grid on;
  146. subplot(2,1,2);
  147. stem(n5, y5);
  148. xlabel('n'); ylabel('y');
  149. title(sprintf('y5(n) output sequence, M = %d', M)); grid on;
  150.  
  151. %% -----------------------------------------------------------------
  152. %% x0(n)=Acos(w0n+theta)
  153. %% -----------------------------------------------------------------
  154. A = 3;
  155. w0 = 0.2*pi;
  156. theta = 0;
  157.  
  158. n0 = n1;
  159.  
  160. x0 = A * cos(w0*n0+theta);
  161.  
  162. yss = filter(b, a, x0);
  163. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.18.6 M = %d',M));
  164. set(gcf,'Color','white');
  165. subplot(2,1,1);
  166. stem(n0, x0);
  167. xlabel('n'); ylabel('x');
  168. title(sprintf('x0(n) input sequence, M = %d', M)); grid on;
  169. subplot(2,1,2);
  170. stem(n0, yss);
  171. xlabel('n'); ylabel('y');
  172. title(sprintf('yss(n) output sequence, M = %d', M)); grid on;

  运行结果:

1、LTI系统的频率响应

第1小题:

第2小题:

第3小题:

第4小题:

第5小题:

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

  1. 《DSP using MATLAB》Problem 6.18

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

  2. 《DSP using MATLAB》Problem 5.18

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

  3. 《DSP using MATLAB》Problem 4.18

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

  4. 《DSP using MATLAB》Problem 2.18

    1.代码: function [y, H] = conv_tp(h, x) % Linear Convolution using Toeplitz Matrix % ----------------- ...

  5. 《DSP using MATLAB》Problem 8.18

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

  6. 《DSP using MATLAB》Problem 5.15

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

  7. 《DSP using MATLAB》Problem 4.15

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

  8. 《DSP using MATLAB》Problem 7.27

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

  9. 《DSP using MATLAB》Problem 7.26

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

随机推荐

  1. 我为什么放弃使用mybatis3的mapper注解了

    原文链接 最近在使用MyBatis3做项目.在使用注解实现Mapper的时候遇到了比较奇葩的问题:在实现数据的batch insert的时候总是报错.好不容易可以正常插入了,但是又不能返回自增的主键i ...

  2. 你的centos/linux下有多个php.ini,不确定是哪个时

    你的centos/linux下有多个php.ini,不确定是哪个时,但是你自己知道,你的php安装目录. 比如我的php安装目录是 /usr/local/php 那么可以通过命令来查找php.ini的 ...

  3. English trip -- MC(情景课)3 D

    xu言: have a nice weekend... sentences How many people are there in you family? they are 3 people in ...

  4. python-day49--前端 html

    一.列表标签 1.有序列表 <ol>       (order list ) 在浏览器中显示包括:padding , 有序排列     <li>:列表中的每一项. 2.无序列表 ...

  5. POJ 3481 SBT做法

    第三次做此题.. 不解释啦. 不过变成用SBT来做啦! SBT好处在于能够保证树的高度为lgn,真真正正的平衡二叉树. 因此删除,插入操作与普通二叉树几乎相同. #include <cstdio ...

  6. 基于嵌入式Linux的千兆以太网卡驱动程序设计及测试

    一. 引言 千兆以太网是一种具有高带宽和高响应的新网络技术,相关协议遵循IEEE 802.3规范标准.采用和10M以太网相似的帧格式.网络协议和布线系统,基于光纤和短距离同轴电缆的物理层介质,更适用于 ...

  7. SQL Server 调优系列进阶篇 - 如何重建数据库索引

    随着数据的数据量的急剧增加,数据库的性能也会明显的有些缓慢这个时候你可以考虑下重建索引或是重新组织索引了. DBCC SHOWCONTIG('表名') 可以查看当前表的索引碎情况. 重建索引 方法一: ...

  8. FormShortCut MainForm 和 二级FORM

    发现,主FORM 定义的快捷键,在二级FORM里也有效. 反过来,就无效. 这样的话,就要考虑 快捷键的冲突问题 了,本来以为不同的FORM 是独立的. http://codeverge.com/em ...

  9. tf.nn的conv2d卷积与max_pool池化

    tf.nn.conv2d(value,filter,strides,[...]) 对于图片来说 value :   形状通常是np.array()类型的4维数组也称tensor(张量),  (batc ...

  10. js 常用事件

    onclick 事件会在对象被点击时发生. 请注意, onclick 与 onmousedown 不同.单击事件是在同一元素上发生了鼠标按下事件之后又发生了鼠标放开事件时才发生的. 如:点击验证码时进 ...