7月底,又一个夏天,又一个火热的夏天,来到火炉城武汉,天天高温橙色预警,到今天已有二十多天。

先看看住的地方

下雨的时候是这样的

接着做题

代码:

  1. %% ------------------------------------------------------------------------
  2. %% Output Info about this m-file
  3. fprintf('\n***********************************************************\n');
  4. fprintf(' <DSP using MATLAB> Problem 8.27 \n\n');
  5.  
  6. banner();
  7. %% ------------------------------------------------------------------------
  8.  
  9. Fp = 100; % analog passband freq in Hz
  10. Fs = 150; % analog stopband freq in Hz
  11. fs = 1000; % sampling rate in Hz
  12.  
  13. % -------------------------------
  14. % ω = ΩT = 2πF/fs
  15. % Digital Filter Specifications:
  16. % -------------------------------
  17. wp = 2*pi*Fp/fs; % digital passband freq in rad/sec
  18. %wp = Fp;
  19. ws = 2*pi*Fs/fs; % digital stopband freq in rad/sec
  20. %ws = Fs;
  21. Rp = 1.0; % passband ripple in dB
  22. As = 30; % stopband attenuation in dB
  23.  
  24. Ripple = 10 ^ (-Rp/20) % passband ripple in absolute
  25. Attn = 10 ^ (-As/20) % stopband attenuation in absolute
  26.  
  27. % Analog prototype specifications: Inverse Mapping for frequencies
  28. T = 1/fs; % set T = 1
  29. OmegaP = wp/T; % prototype passband freq
  30. OmegaS = ws/T; % prototype stopband freq
  31.  
  32. % Analog Butterworth Prototype Filter Calculation:
  33. [cs, ds] = afd_butt(OmegaP, OmegaS, Rp, As);
  34.  
  35. % Calculation of second-order sections:
  36. fprintf('\n***** Cascade-form in s-plane: START *****\n');
  37. [CS, BS, AS] = sdir2cas(cs, ds)
  38. fprintf('\n***** Cascade-form in s-plane: END *****\n');
  39.  
  40. % Calculation of Frequency Response:
  41. [db_s, mag_s, pha_s, ww_s] = freqs_m(cs, ds, 2*pi/T);
  42.  
  43. % Calculation of Impulse Response:
  44. [ha, x, t] = impulse(cs, ds);
  45.  
  46. % Match-z Transformation:
  47. %[b, a] = imp_invr(cs, ds, T) % digital Num and Deno coefficients of H(z)
  48. [b, a] = mzt(cs, ds, T) % digital Num and Deno coefficients of H(z)
  49. [C, B, A] = dir2par(b, a)
  50.  
  51. % Calculation of Frequency Response:
  52. [db, mag, pha, grd, ww] = freqz_m(b, a);
  53.  
  54. %% -----------------------------------------------------------------
  55. %% Plot
  56. %% -----------------------------------------------------------------
  57. figure('NumberTitle', 'off', 'Name', 'Problem 8.27 Analog Butterworth lowpass')
  58. set(gcf,'Color','white');
  59. M = 1.2; % Omega max
  60.  
  61. subplot(2,2,1); plot(ww_s/pi*T, mag_s); grid on; axis([-1.5, 1.5, 0, 1.1]);
  62. xlabel(' Analog frequency in k\pi units'); ylabel('|H|'); title('Magnitude in Absolute');
  63. set(gca, 'XTickMode', 'manual', 'XTick', [-500, -300, 0, 200, 300, 1000]*T);
  64. set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.0316, 0.5, 0.8913, 1]);
  65.  
  66. subplot(2,2,2); plot(ww_s/pi*T, db_s); grid on; %axis([0, M, -50, 10]);
  67. xlabel('Analog frequency in k\pi units'); ylabel('Decibels'); title('Magnitude in dB ');
  68. %set(gca, 'XTickMode', 'manual', 'XTick', [-0.3, -0.2, 0, 0.2, 0.3, 1.0]);
  69. set(gca, 'YTickMode', 'manual', 'YTick', [-65, -30, -1, 0]);
  70. set(gca,'YTickLabelMode','manual','YTickLabel',['65';'30';' 1';' 0']);
  71.  
  72. subplot(2,2,3); plot(ww_s/pi*T, pha_s/pi); grid on; axis([-1.010, 1.010, -1.2, 1.2]);
  73. xlabel('Analog frequency in k\pi nuits'); ylabel('radians'); title('Phase Response');
  74. set(gca, 'XTickMode', 'manual', 'XTick', [-0.3, -0.2, 0, 0.2, 0.3, 1.0]);
  75. set(gca, 'YTickMode', 'manual', 'YTick', [-1:0.5:1]);
  76.  
  77. subplot(2,2,4); plot(t, ha); grid on; %axis([0, 30, -0.05, 0.25]);
  78. xlabel('time in seconds'); ylabel('ha(t)'); title('Impulse Response');
  79.  
  80. figure('NumberTitle', 'off', 'Name', 'Problem 8.27 Digital Butterworth lowpass')
  81. set(gcf,'Color','white');
  82. M = 2; % Omega max
  83.  
  84. %% Note %%
  85. %% Magnitude of H(z) * T
  86. %% Note %%
  87. subplot(2,2,1); plot(ww/pi, mag/fs); axis([0, M, 0, 1.1]); grid on;
  88. xlabel(' frequency in \pi units'); ylabel('|H|'); title('Magnitude Response');
  89. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.2, 0.3, 1.0, M]);
  90. set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.0316, 0.5, 0.8913, 1]);
  91.  
  92. subplot(2,2,2); plot(ww/pi, pha/pi); axis([0, M, -1.1, 1.1]); grid on;
  93. xlabel('frequency in \pi nuits'); ylabel('radians in \pi units'); title('Phase Response');
  94. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.2, 0.3, 1.0, M]);
  95. set(gca, 'YTickMode', 'manual', 'YTick', [-1:1:1]);
  96.  
  97. subplot(2,2,3); plot(ww/pi, db); axis([0, M, -120, 10]); grid on;
  98. xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude in dB ');
  99. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.2, 0.3, 1.0, M]);
  100. set(gca, 'YTickMode', 'manual', 'YTick', [-70, -30, -1, 0]);
  101. set(gca,'YTickLabelMode','manual','YTickLabel',['70';'30';' 1';' 0']);
  102.  
  103. subplot(2,2,4); plot(ww/pi, grd); grid on; %axis([0, M, 0, 35]);
  104. xlabel('frequency in \pi units'); ylabel('Samples'); title('Group Delay');
  105. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.2, 0.3, 1.0, M]);
  106. %set(gca, 'YTickMode', 'manual', 'YTick', [0:5:35]);
  107.  
  108. figure('NumberTitle', 'off', 'Name', 'Problem 8.27 Pole-Zero Plot')
  109. set(gcf,'Color','white');
  110. zplane(b,a);
  111. title(sprintf('Pole-Zero Plot'));
  112. %pzplotz(b,a);
  113.  
  114. % Calculation of Impulse Response:
  115. %[hs, xs, ts] = impulse(c, d);
  116. figure('NumberTitle', 'off', 'Name', 'Problem 8.27 Imp & Freq Response')
  117. set(gcf,'Color','white');
  118. t = [0:0.001:0.07]; subplot(2,1,1); impulse(cs,ds,t); grid on; % Impulse response of the analog filter
  119. axis([0, 0.07, -100, 250]);hold on
  120.  
  121. n = [0:1:0.07/T]; hn = filter(b,a,impseq(0,0,0.07/T)); % Impulse response of the digital filter
  122. stem(n*T,hn); xlabel('time in sec'); title (sprintf('Impulse Responses, T=%.3f',T));
  123. hold off
  124.  
  125. %n = [0:1:29];
  126. %hz = impz(b, a, n);
  127.  
  128. % Calculation of Frequency Response:
  129. [dbs, mags, phas, wws] = freqs_m(cs, ds, 2*pi/T); % Analog frequency s-domain
  130.  
  131. [dbz, magz, phaz, grdz, wwz] = freqz_m(b, a); % Digital z-domain
  132.  
  133. %% -----------------------------------------------------------------
  134. %% Plot
  135. %% -----------------------------------------------------------------
  136.  
  137. M = 1/T; % Omega max
  138.  
  139. subplot(2,1,2); plot(wws/(2*pi),mags*fs,'b', wwz/(2*pi)*fs,magz,'r'); grid on;
  140.  
  141. xlabel('frequency in Hz'); title('Magnitude Responses'); ylabel('Magnitude');
  142.  
  143. text(1.4,.5,'Analog filter'); text(1.5,1.5,'Digital filter');

  运行结果:

绝对指标

非归一化Butterworth模拟低通直接形式的系数

模拟低通串联形式的系数

开始Match-z方法,转变成数字低通

数字低通直接形式的系数

数字低通的并联形式的系数

模拟Butterworth低通的幅度谱、相位谱和脉冲响应

经过Match-z方法得到的数字Butterworth低通的幅度谱、相位谱和群延迟

数字Butterworth低通的零极点图

模拟Butterworth低通、Match-z方法得到的数字Butterworth低通,二者的脉冲响应、幅度响应如下

从上图可以看出,Match-z方法得到的数字低通,其脉冲响应与原模拟脉冲响应似乎有延迟的效果;其不像脉冲响应不变法那样,数字低通的

脉冲响应是相应模拟低通脉冲响应的采样序列,即保持了脉冲响应形式不变。

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

  1. 《DSP using MATLAB》Problem 7.27

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

  2. 《DSP using MATLAB》Problem 5.27

    代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Outp ...

  3. 《DSP using MATLAB》Problem 7.23

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

  4. 《DSP using MATLAB》Problem 7.16

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

  5. 《DSP using MATLAB》Problem 7.38

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

  6. 《DSP using MATLAB》Problem 7.36

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

  7. 《DSP using MATLAB》Problem 7.32

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

  8. 《DSP using MATLAB》Problem 7.31

    参照Example7.27,因为0.1π=2πf1   f1=0.05,0.9π=2πf2   f2=0.45 所以0.1π≤ω≤0.9π,0.05≤|H|≤0.45 代码: %% +++++++++ ...

  9. 《DSP using MATLAB》Problem 7.26

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

随机推荐

  1. 007-Java可变个数形参重载【数组和...】

    重载方法时,可变个数形参的方法有两种方式 数组重载 ...重载 对两种方法,其实是一致的,示例如下: public class MethodArgsTest { //可变个数形参的格式:数据类型... ...

  2. 使用雪碧图Css Sprite精灵 | 加速网页响应速度

    什么是CSS Sprite精灵? 是用于前端的一种图片应用技术,通常情况,我们的开发的网页或许有很多张图片,假如在一个页面上有50多张小图片,这意味着浏览器要逐个下载50张图片.Css Sprite它 ...

  3. CSIC_716_20191112【闭包函数和装饰器】

    闭包函数 什么是闭包函数:闭包函数是函数嵌套.函数对象.名称空间和作用域的集合体. 闭包函数必须在函数内部定义,闭包函数可以引用外层函数的名字. # _*_ coding: gbk _*_ # @Au ...

  4. Mysql 权限命令整理大全

    mysql show slave status 需要什么权限 grant replication client on *.* to 'user_name'@'%';

  5. Photoshop基本操作

    PS 工具是我们使用频率比较高的软件之一, 我们学习PS目的不是为了设计海报做电商和UI的,而是要求: 会简单的抠图 会简单的修改PSD效果图 熟练的切图 能和网站美工美眉有共同话题..... Pho ...

  6. C++Builder常用函数

    BCB函数集 1.内存分配     函数名称 AllocMem 函数说明 在队中分配指定字节的内存块,并将分配的每一个字节初始化为 0.函数原型如下: void * __fastcall AllocM ...

  7. mfcs100d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in MSVCRTD.lib(dllmain.obj)

    转自VC错误:http://www.vcerror.com/?p=55 问题描述: mfcs100d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 al ...

  8. iOS之NSArray类簇简介-(copy、mutableCopy导致程序crash)

    1.前言 开发时常常用数组对数据进行处理,对NSMutableArray进行操作时经常导致程序崩溃,特研究一下NSArray的类簇!涉及__NSPlaceholderArray.__NSArray0. ...

  9. MailHelper

    using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Co ...

  10. PAT甲级——A1121 Damn Single【25】

    "Damn Single (单身狗)" is the Chinese nickname for someone who is being single. You are suppo ...