代码:

  1. %% ------------------------------------------------------------------------
  2. %% Output Info about this m-file
  3. fprintf('\n***********************************************************\n');
  4. fprintf(' <DSP using MATLAB> Problem 3.22 \n\n');
  5.  
  6. banner();
  7. %% ------------------------------------------------------------------------
  8.  
  9. %% -------------------------------------------------------------------
  10. %% 1 xa(t)=cos(20πt+θ) through A/D
  11. %% -------------------------------------------------------------------
  12. Ts = 0.05; % sample interval, 0.05s
  13. Fs = 1/Ts; % Fs=20Hz
  14. %theta = 0;
  15. %theta = pi/6;
  16. %theta = pi/4;
  17. %theta = pi/3;
  18. theta = pi/2;
  19.  
  20. n1_start = 0; n1_end = 20;
  21. n1 = [n1_start:1:n1_end];
  22. nTs = n1 * Ts; % [0, 1]s
  23.  
  24. x1 = cos(20*pi*nTs + theta * ones(1,length(n1))); % Digital signal
  25.  
  26. M = 500;
  27. [X1, w] = dtft1(x1, n1, M);
  28.  
  29. magX1 = abs(X1); angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1);
  30.  
  31. %% --------------------------------------------------------------------
  32. %% START X(w)'s mag ang real imag
  33. %% --------------------------------------------------------------------
  34. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 X1, theta/pi = %f', theta/pi));
  35. set(gcf,'Color','white');
  36. subplot(2,1,1); plot(w/pi,magX1); grid on; %axis([-1,1,0,1.05]);
  37. title('Magnitude Response');
  38. xlabel('frequency in \pi units'); ylabel('Magnitude |H|');
  39. subplot(2,1,2); plot(w/pi, angX1/pi); grid on; %axis([-1,1,-1.05,1.05]);
  40. title('Phase Response');
  41. xlabel('frequency in \pi units'); ylabel('Radians/\pi');
  42.  
  43. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 X1, theta/pi = %f', theta/pi));
  44. set(gcf,'Color','white');
  45. subplot(2,1,1); plot(w/pi, realX1); grid on;
  46. title('Real Part');
  47. xlabel('frequency in \pi units'); ylabel('Real');
  48. subplot(2,1,2); plot(w/pi, imagX1); grid on;
  49. title('Imaginary Part');
  50. xlabel('frequency in \pi units'); ylabel('Imaginary');
  51. %% -------------------------------------------------------------------
  52. %% END X's mag ang real imag
  53. %% -------------------------------------------------------------------
  54.  
  55. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 xa(n), theta/pi = %f and x1(n)', theta/pi));
  56. na1 = 0:0.01:1;
  57. xa1 = cos(20 * pi * na1 + theta * ones(1,length(na1)));
  58. set(gcf, 'Color', 'white');
  59. plot(1000*na1,xa1); grid on; %axis([0,1,0,1.5]);
  60. title('x1(n) and xa(n)');
  61. xlabel('t in msec.'); ylabel('xa(t)'); hold on;
  62. plot(1000*nTs, x1, 'o'); hold off;
  63.  
  64. %% ------------------------------------------------------------
  65. %% xa(t) reconstruction from x1(n)
  66. %% ------------------------------------------------------------
  67.  
  68. Dt = 0.001; t = 0:Dt:1;
  69. xa = x1 * sinc(Fs*(ones(length(n1),1)*t - nTs'*ones(1,length(t)))) ;
  70.  
  71. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 Reconstructed From x1(n), theta/pi = %f', theta/pi));
  72. set(gcf,'Color','white');
  73. %subplot(2,1,1);
  74. stairs(t*1000,xa,'r'); grid on; %axis([0,1,0,1.5]); % Zero-Order-Hold
  75. title('Reconstructed Signal from x1(n) using Zero-Order-Hold');
  76. xlabel('t in msec.'); ylabel('xa(t)'); hold on;
  77. %stem(nTs*1000, x1); gtext('ZOH'); hold off;
  78. plot(nTs*1000, x1, 'o'); gtext('ZOH'); hold off;
  79.  
  80. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 Reconstructed From x1(n), theta/pi = %f', theta/pi));
  81. set(gcf,'Color','white');
  82. %subplot(2,1,2);
  83. plot(t*1000,xa,'r'); grid on; %axis([0,1,0,1.5]); % first-Order-Hold
  84. title('Reconstructed Signal from x1(n) using First-Order-Hold');
  85. xlabel('t in msec.'); ylabel('xa(t)'); hold on;
  86. plot(nTs*1000,x1,'o'); gtext('FOH'); hold off;
  87.  
  88. xa = spline(nTs, x1, t);
  89. figure('NumberTitle', 'off', 'Name', sprintf('Problem 3.22 Reconstructed From x1(n), theta/pi = %f', theta/pi));
  90. set(gcf,'Color','white');
  91. %subplot(2,1,1);
  92. plot(1000*t, xa,'r');
  93. xlabel('t in ms units'); ylabel('x');
  94. title(sprintf('Reconstructed Signal from x1(n) using Spline function')); grid on; hold on;
  95. plot(1000*nTs, x1,'o'); gtext('spline');

  运行结果:

这里只看初相位为0的情况,原始模拟信号和采样信号(样点值圆圈标示):

采样信号的谱,模拟角频率20π对应的数字角频率为π,如下图所示:

用采样信号重建原来模拟信号:

sinc方法,stairs函数画图

sinc方法,plot函数画图:

cubic方法

其他初相位的情况,这里不上图了。

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

  1. 《DSP using MATLAB》Problem 6.22

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

  2. 《DSP using MATLAB》Problem 5.22

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

  3. 《DSP using MATLAB》Problem 8.22

    时光飞逝,亲朋会一个一个离我们远去,孤独漂泊一阵子后,我们自己也要离开, 代码: %% -------------------------------------------------------- ...

  4. 《DSP using MATLAB》Problem 7.25

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

  5. 《DSP using MATLAB》Problem 3.1

    先写DTFT子函数: function [X] = dtft(x, n, w) %% --------------------------------------------------------- ...

  6. 《DSP using MATLAB》Problem 7.29

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

  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.24

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

随机推荐

  1. English trip V1 - 8.What's in My Bag? 我的包里面有什么? Teacher:Corrine Key: plular(复数) and singular(单数)

    In this lesson you will learn to talk about the things you have.   您将学习如何谈论您拥有的东西 课上内容(Lesson) What' ...

  2. Confluence 6 教程:在 Confluence 中导航

    当你对 Confluence 有所了解后,你会发现 Confluence 使用起来非常简单.这个教程主要是针对你使用的 Confluence 界面进行一些说明,同时向你展示在那里可以进行一些通用的任务 ...

  3. hdu4847 kmp

    Chen, Adrian (November 7, 2013). “Doge Is An Ac- tually Good Internet Meme. Wow.”. Gawker. Retrieved ...

  4. oracle 产生一个任意大小的随机数

    SELECT DBMS_RANDOM.RANDOM FROM DUAL;          产生一个任意大小的随机数 SELECT ABS(MOD(DBMS_RANDOM.RANDOM,100)) F ...

  5. idea开发工具安装说明

    开发工具安装说明   安装JDK1.8 第一步,双击"jdk-8u45-windows-i586.exe"安装文件,进行安装,具体安装过程如下图所示: 第二步,右键我的电脑-属性- ...

  6. 微信小程序通过js动态修改css样式的方法(交流QQ群:604788754)

    WXML <view class="page" style="background-color:{{pageBackgroundColor}}" > ...

  7. POJ 2886 线段树单点更新

    转载自:http://blog.csdn.net/sdj222555/article/details/6878651 反素数拓展参照:http://blog.csdn.net/ACdreamers/a ...

  8. .net下4款不错的微信SDK

    .net下4款不错的微信SDK: 一款值得推荐的.Net微信开发SDK http://www.17ky.net/soft/474.html.Net微信公开帐号接口 WeiXinSDK http://w ...

  9. Tomcat 域名绑定多个Host配置要点

    一.在server.xml中添加Host节点,name就是需要绑定的域名,多个域名在Host节点下建立<Alias></Alias>子节点,可建立多个. <Engine ...

  10. c++模板函数声明定义分离编译错误详解

    今天看到accelerated c++上有个简单的vector容器的实现Vec,就再vs2008上编译了下: ///// Vec.h #ifndef GUARD_VEC_H #define GUARD ...