只放第1小题。

代码:

  1. %% ------------------------------------------------------------------------
  2. %% Output Info about this m-file
  3. fprintf('\n***********************************************************\n');
  4. fprintf(' <DSP using MATLAB> Problem 9.4.1 \n\n');
  5.  
  6. banner();
  7. %% ------------------------------------------------------------------------
  8.  
  9. % ------------------------------------------------------------
  10. % PART 1
  11. % ------------------------------------------------------------
  12.  
  13. % Discrete time signal
  14.  
  15. n1_start = 0; n1_end = 100;
  16. n1 = [n1_start:1:n1_end];
  17.  
  18. xn1 = cos(0.15*pi*n1); % digital signal
  19.  
  20. D = 4; % downsample by factor D
  21. OFFSET = 0;
  22. y = downsample(xn1, D, OFFSET);
  23. ny = [n1_start:n1_end/D];
  24. % ny = [n1_start:n1_end/D-1]; % OFFSET=2
  25.  
  26. figure('NumberTitle', 'off', 'Name', 'Problem 9.4.1 xn1 and y')
  27. set(gcf,'Color','white');
  28. subplot(2,1,1); stem(n1, xn1, 'b');
  29. xlabel('n'); ylabel('x(n)');
  30. title('xn1 original sequence'); grid on;
  31. subplot(2,1,2); stem(ny, y, 'r');
  32. xlabel('ny'); ylabel('y(n)');
  33. title(sprintf('y sequence, downsample by D=%d offset=%d', D, OFFSET)); grid on;
  34.  
  35. % ----------------------------
  36. % DTFT of xn1
  37. % ----------------------------
  38. M = 500;
  39. [X1, w] = dtft1(xn1, n1, M);
  40.  
  41. magX1 = abs(X1); angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1);
  42. max(magX1)
  43.  
  44. %% --------------------------------------------------------------------
  45. %% START X(w)'s mag ang real imag
  46. %% --------------------------------------------------------------------
  47. figure('NumberTitle', 'off', 'Name', 'Problem 9.4.1 X1 DTFT');
  48. set(gcf,'Color','white');
  49. subplot(2,1,1); plot(w/pi,magX1); grid on; %axis([-2, -1, -0.5, 0, 0.15, 0.5, 1, 2]);
  50. title('Magnitude Response');
  51. xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
  52. set(gca, 'xtick', [-2,-1.85,-1.5,-1,-0.15,0,0.15,0.5,1,1.5,1.85,2]);
  53. subplot(2,1,2); plot(w/pi, angX1/pi); grid on; %axis([-1,1,-1.05,1.05]);
  54. title('Phase Response');
  55. xlabel('digital frequency in \pi units'); ylabel('Radians/\pi');
  56.  
  57. figure('NumberTitle', 'off', 'Name', 'Problem 9.4.1 X1 DTFT');
  58. set(gcf,'Color','white');
  59. subplot(2,1,1); plot(w/pi, realX1); grid on;
  60. title('Real Part');
  61. xlabel('digital frequency in \pi units'); ylabel('Real');
  62. subplot(2,1,2); plot(w/pi, imagX1); grid on;
  63. title('Imaginary Part');
  64. xlabel('digital frequency in \pi units'); ylabel('Imaginary');
  65. %% -------------------------------------------------------------------
  66. %% END X's mag ang real imag
  67. %% -------------------------------------------------------------------
  68.  
  69. % ----------------------------
  70. % DTFT of y
  71. % ----------------------------
  72. M = 500;
  73. [Y, w] = dtft1(y, ny, M);
  74.  
  75. magY_DTFT = abs(Y); angY_DTFT = angle(Y); realY_DTFT = real(Y); imagY_DTFT = imag(Y);
  76. max(magY_DTFT)
  77. ratio = max(magX1)/max(magY_DTFT)
  78.  
  79. %% --------------------------------------------------------------------
  80. %% START Y(w)'s mag ang real imag
  81. %% --------------------------------------------------------------------
  82. figure('NumberTitle', 'off', 'Name', 'Problem 9.4.1 Y DTFT');
  83. set(gcf,'Color','white');
  84. subplot(2,1,1); plot(w/pi, magY_DTFT); grid on; %axis([-2,2, -1, 2]);
  85. title('Magnitude Response');
  86. xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
  87. set(gca, 'xtick', [-2,-1.4,-1,-0.6,0,0.6,1,1.4,2]);
  88. subplot(2,1,2); plot(w/pi, angY_DTFT/pi); grid on; %axis([-1,1,-1.05,1.05]);
  89. title('Phase Response');
  90. xlabel('digital frequency in \pi units'); ylabel('Radians/\pi');
  91.  
  92. figure('NumberTitle', 'off', 'Name', 'Problem 9.4.1 Y DTFT');
  93. set(gcf,'Color','white');
  94. subplot(2,1,1); plot(w/pi, realY_DTFT); grid on;
  95. title('Real Part');
  96. xlabel('digital frequency in \pi units'); ylabel('Real');
  97. subplot(2,1,2); plot(w/pi, imagY_DTFT); grid on;
  98. title('Imaginary Part');
  99. xlabel('digital frequency in \pi units'); ylabel('Imaginary');
  100. %% -------------------------------------------------------------------
  101. %% END Y's mag ang real imag
  102. %% -------------------------------------------------------------------
  103.  
  104. figure('NumberTitle', 'off', 'Name', sprintf('Problem 9.4.1 X1 & Y--DTFT of x and y, D=%d offset=%d', D,OFFSET));
  105. set(gcf,'Color','white');
  106. subplot(2,1,1); plot(w/pi,magX1); grid on; %axis([-1,1,0,1.05]);
  107. title('Magnitude Response');
  108. xlabel('digital frequency in \pi units'); ylabel('Magnitude |H|');
  109. set(gca, 'xtick', [-2,-1.85,-1.4,-1,-0.6,-0.5,-0.15,0,0.15,0.5,0.6,1,1.4,1.85,2]);
  110. set(gca, 'ytick', [-0.2, 0, 13.5, 20, 40, 51, 60]);
  111. hold on;
  112. plot(w/pi, magY_DTFT, 'r'); gtext('magY(\omega)', 'Color', 'r');
  113. hold off;
  114.  
  115. subplot(2,1,2); plot(w/pi, angX1/pi); grid on; %axis([-1,1,-1.05,1.05]);
  116. title('Phase Response');
  117. xlabel('digital frequency in \pi units'); ylabel('Radians/\pi');
  118. hold on;
  119. plot(w/pi, angY_DTFT/pi, 'r'); gtext('AngY(\omega)', 'Color', 'r');
  120. hold off;

  运行结果:

分两种情况

1、按照D=4抽取,offset=0

原始序列,抽取序列

原始序列的谱

抽取序列的谱

二者的DTFT混叠到一起,红颜色曲线是抽取序列的DTFT,可看出,其幅度大致为原始序列的谱幅度的1/4(精确值是1/3.7778)。

2、按照D=4抽取,offset=2

二者的DTFT混叠到一起,红颜色曲线是抽取序列的DTFT,可看出,其幅度大致为原始序列的谱幅度的1/4(精确值是1/4.0699)。

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

  1. 《DSP using MATLAB》Problem 7.27

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

  2. 《DSP using MATLAB》Problem 7.26

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

  3. 《DSP using MATLAB》Problem 7.25

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

  4. 《DSP using MATLAB》Problem 7.24

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

  5. 《DSP using MATLAB》Problem 7.23

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

  6. 《DSP using MATLAB》Problem 7.16

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

  7. 《DSP using MATLAB》Problem 7.15

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

  8. 《DSP using MATLAB》Problem 7.14

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

  9. 《DSP using MATLAB》Problem 7.13

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

  10. 《DSP using MATLAB》Problem 7.12

    阻带衰减50dB,我们选Hamming窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

随机推荐

  1. docker 镜像中心搭建

    1.由于国外镜像很慢,所以用了网易蜂巢的镜像docker pull hub.c.163.com/library/registry:2.5.2本地的存储空间挂载到容器内部,持久保存镜像中心文件docke ...

  2. sublime 文件无法拖放

    sublime 文件无法拖放解决方法 https://github.com/emetio/pyv8-binaries 解决: 1. 去gihub下载 PyV8,连接地址:https://github. ...

  3. UVA 1525 Falling Leaves

    题目链接:https://vjudge.net/problem/UVA-1525 题目链接:https://vjudge.net/problem/POJ-1577 题目大意 略. 分析 建树,然后先序 ...

  4. Kali Linux 2018 更新源配置

    查看添加更新源 编辑sources.list,将kali更新源加入其中 sudo vim /etc/apt/sources.list 国内更新源 #阿里云 deb http://mirrors.ali ...

  5. 关于 CShellManager 的作用

    也许大家看到这个题目,未曾进行windows shell编程的同学呢,会不明白是什么意思,这里简单的介绍一下,windows shell就是可以使编写的程序与系统关联(如快捷方式,托盘图标等),管理系 ...

  6. 注册页面-使用form模块搭建

    基于Django的form模块,快速的搭建注册页面,每个限制条件,都放在form模块里面,不单独对每一项编写标签,使用模版的 for 循环来渲染. 首先设置form模块 在blogs模块下创建一个bl ...

  7. <python练习题>python练习题(常练勿忘)

    学了python,去面试经常出现,某个或某些库不熟悉导则想不起来怎么写,知道思路而写不出来,多半还是不够熟悉,这里就作为熟悉python的地方,多做做题,多思考. 题目1:店铺ID为00000000- ...

  8. hdu6319 Ascending Rating /// 单调队列

    题目大意: 给定n m k,p q r mod, 给出序列的前k项 之后的按公式 a[i]=(p×a[i-1]+q×i+r)%mod 递推 求序列中每个长度为m的连续区间的 该区间最大值与第一位的位置 ...

  9. vue中beforeRouteEnter 执行的时机及运用的误区?

    beforeRouteEnter钩子 beforeRouteEnter (to, from, next) { console.log(this); //undefined,不能用this来获取vue实 ...

  10. C# 获取系统开机时间

    原文:C# 获取系统开机时间 ///         ///  获取系统开机时间          ///         ///         private DateTime GetComput ...