先放子函数:

  1. function [C, B, A, rM] = dir2fs_r(h, r);
  2. % DIRECT-form to Frequency Sampling form conversion
  3. % ----------------------------------------------------------
  4. % [C, B, A, rM] = dir2fs_r(h, r)
  5. % C = Row vector containing gains for parallel sections
  6. % B = matrix containing numerator coefficients arranged in rows
  7. % A = matrix containing denominator coefficients arranged in rows
  8. % h = impulse response vector of an FIR filter
  9. % rM = r^M factor needed in the feedforward loop
  10. % r = radius of the circle over which samples are taken (r<1)
  11.  
  12. M = length(h); H = fft(h, M);
  13. magH = abs(H); phaH = angle(H)';
  14.  
  15. % check even or odd M
  16. if (M == 2*floor(M/2))
  17. L = M/2-1; % M is even
  18. %A1 = [1, -1, 0; 1, 1, 0];
  19. A1 = [1, -r, 0; 1, r, 0];
  20. C1 = [real(H(1)), real(H(L+2))];
  21. else
  22. L = (M-1)/2; % M is odd
  23. %A1 = [1, -1, 0];
  24. A1 = [1, -r, 0];
  25. C1 = [real(H(1))];
  26. end
  27. k = [1:L]';
  28.  
  29. % initialize B and A arrays
  30. B = zeros(L, 2); A = ones(L, 3);
  31. % compute denominator coefficients
  32. A(1:L, 2) = -2*r*cos(2*pi*k/M);
  33. A(1:L, 3) = r*r;
  34. A = [A;A1];
  35. % compute numerator coefficients
  36. B(1:L,1) = cos(phaH(2:L+1));
  37. B(1:L,2) = -r*cos(phaH(2:L+1) - (2*pi*k/M));
  38. % compute gain coefficients
  39. C = [2*magH(2:L+1), C1]';
  40.  
  41. rM = r^M;

  再放主函数:

  1. %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. %% Output Info about this m-file
  3. fprintf('\n***********************************************************\n');
  4. fprintf(' <DSP using MATLAB> Problem 6.20 \n\n');
  5.  
  6. banner();
  7. %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  8. %format long;
  9. format short;
  10. fprintf('\n FIR filter DIRECT-form: \n');
  11. h = [1, 2, 3, 2, 1]/9;
  12.  
  13. b = h
  14. a = 1.0
  15.  
  16. fprintf('\nConvert DIRECT-form to PARALLEL-form : \n');
  17. [C, Bp, Ap] = dir2par(b, a)
  18.  
  19. if size(C)==0
  20. C = 0;
  21. end
  22.  
  23. fprintf('\nConvert DIRECT-form to CASCADE-form : \n');
  24. [b0, Bc, Ac] = dir2cas(b, a)
  25.  
  26. fprintf('\nConvert TF-form to SOS-form : \n');
  27. [sos, g] = tf2sos(b, a)
  28.  
  29. % ----------------------------------------------------------
  30. % NOTE: linear-phase can not use LATTICE-form
  31. % ----------------------------------------------------------
  32. fprintf('\nConvert DIRECT-form to All-Zero LATTICE-form : \n');
  33. [Klc] = dir2latc(b)
  34.  
  35. fprintf('\nConvert DIRECT-form to FREQUENCY-SAMPLE-form 1 : \n');
  36. [Cfs, Bfs, Afs] = dir2fs(b)
  37.  
  38. fprintf('\nConvert DIRECT-form to FREQUENCY-SAMPLE-form 2 : \n');
  39. r = 0.9;
  40. [Cfs_r, Bfs_r, Afs_r, rM] = dir2fs_r(b, r)
  41.  
  42. % -----------------------------------------
  43. % START check
  44. % -----------------------------------------
  45. n = [0:7];
  46. delta = impseq(0, 0, 7)
  47. %format long
  48. format short
  49. hcas = casfiltr(b0, Bc, Ac, delta)
  50.  
  51. hltc = latcfilt(Klc, delta)
  52.  
  53. %hladr = ladrfilt(Klr, Clr, delta)
  54.  
  55. hdir = filter(b, a, delta)
  56. % -------------------------------------------
  57. % END check
  58. % -------------------------------------------

  运行结果:

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

  1. 《DSP using MATLAB》Problem 5.20

    窗外的知了叽叽喳喳叫个不停,屋里温度应该有30°,伏天的日子难过啊! 频率域的方法来计算圆周移位 代码: 子函数的 function y = cirshftf(x, m, N) %% -------- ...

  2. 《DSP using MATLAB》Problem 4.20

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

  3. 《DSP using MATLAB》Problem 3.20

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

  4. 《DSP using MATLAB》Problem 2.20

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

  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 6.15

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

  8. 《DSP using MATLAB》Problem 6.12

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

  9. 《DSP using MATLAB》Problem 6.10

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

随机推荐

  1. 逆袭之旅DAY.XIA.Object中常用方法

    2018-07-31

  2. Python之路-python基础二

    本章内容:      一.编码格式      二.常用数据类型      三.字符串常用方法      四.列表常用方法  五.数据运算      六.课后作业 编码格式:       ASCII A ...

  3. It is never too late!

    整理着过去的学习笔记,零零碎碎的,偶尔夹杂着当时的心境. 泛泛的学着东西,不很系统,不很深入,倒像是在拾海,有时捡捡贝壳,有时抓抓螃蟹.叹服大海的神奇,还没来得及深钻某个领域. (以下内容写于2016 ...

  4. python全栈开发笔记-----------概要

    Python开发 开发: 开发语言: 高级语言:python.Java.php  .C#   .Go .ruby . C++ .... ===>字节码 低级语言:C.汇编            ...

  5. Django 数据库连接配置(Oracle、Mysql)

    一.Django Oracle连接配置 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.oracle', 'NAME': 'DEMO' ...

  6. vue-4-Class 与 Style 绑定

    v-if <h1 v-if="ok">Yes</h1> 切换多个元素://最终的渲染结果不会包含 <template> 元素 <templ ...

  7. 关于学习Vue的前置工作/技术储备

    关于学习Vue的前置工作/技术储备 1.GitBatch 2.Sublime Text 3.Node-----npm 命令 本人用的idea GitBatch: GitBatch是一个可以编写shel ...

  8. pytorch加载和保存模型

    在模型完成训练后,我们需要将训练好的模型保存为一个文件供测试使用,或者因为一些原因我们需要继续之前的状态训练之前保存的模型,那么如何在PyTorch中保存和恢复模型呢? 方法一(推荐): 第一种方法也 ...

  9. 关于Java课堂实验中的一些总结(Scanner)

    import java.util.Scanner; 这个头文件是java里面用来输入东西的,就相当于c++里面的iostream输入流...?暂且这么理解吧 然后使用方法:Scanner in = n ...

  10. 界面控件DevExpress发布v18.2.5|附下载

    DevExpress Universal Subscription(又名DevExpress宇宙版或DXperience Universal Suite)是全球使用广泛的.NET用户界面控件套包,De ...