今天下了小雨,空气中泛起潮湿的味道,阴冷的感觉袭来,心情受到小小影响。

代码:

hp2lpfre子函数

  1. function [wpLP, wsLP, alpha] = hp2lpfre(wphp, wshp)
  2. % Band-edge frequency conversion from highpass to lowpass digital filter
  3. % -------------------------------------------------------------------------
  4. % [wpLP, wsLP, alpha] = hp2lpfre(wphp, wshp)
  5. % wpLP = passband edge for the lowpass digital prototype
  6. % wsLP = stopband edge for the lowpass digital prototype
  7. % alpha = lowpass to highpass transformation parameter
  8. % wphp = passband edge frequency for the highpass
  9. % wshp = stopband edge frequency for the highpass
  10. %
  11. %
  12. if wphp <= 0
  13. error('Passband edge must be larger than 0.')
  14. end
  15.  
  16. if wshp >= wphp
  17. error('Stopband edge must be smaller then Passband edge')
  18. end
  19.  
  20. % Determine the digital lowpass cutoff frequencies:
  21. wpLP = 0.2*pi;
  22. alpha = -(cos((wpLP + wphp)/2))/(cos((wpLP - wphp)/2));
  23. wsLP = angle(-(exp(-j*wshp)+alpha)/(1+alpha*exp(-j*wshp)));

  dhpfd_bl子函数

  1. function [b, a] = dhpfd_bl(type, wp, ws, Rp, As)
  2. % IIR Highpass Filter Design using bilinear transformation
  3. % -----------------------------------------------------------------------
  4. % [b, a] = dhpfd_bl(type, wp, ws, Rp, As);
  5. % type = 'butter' or 'cheby1' or 'cheby2' or 'ellip'
  6. % b = numerator polynomial coefficients of highpass filter , Direct form
  7. % a = denominator polynomial coefficients of highpass filter, Direct form
  8. % wp = Passband edge frequency in radians;
  9. % ws = Stopband edge frequency in radians (wp < ws);
  10. % Rp = Passband ripple in +dB; Rp > 0
  11. % As = Stopband attenuation in +dB; As > 0
  12. %
  13. %
  14. if isempty(type)
  15. str = 'butter';
  16. end
  17.  
  18. switch type
  19. case 'butter'
  20. [b , a] = butthpf(wp, ws, Rp, As); break;
  21. case 'cheby1'
  22. [b , a] = cheb1hpf(wp, ws, Rp, As); break;
  23. case 'cheby2'
  24. [b , a] = cheb2hpf(wp, ws, Rp, As); break;
  25. case 'ellip'
  26. [b , a] = eliphpf(wp, ws, Rp, As); break;
  27. otherwise
  28. disp('Oh, input may be error!\n');
  29. end

  

  1. %% ------------------------------------------------------------------------
  2. %% Output Info about this m-file
  3. fprintf('\n***********************************************************\n');
  4. fprintf(' <DSP using MATLAB> Problem 8.34 \n\n');
  5.  
  6. banner();
  7. %% ------------------------------------------------------------------------
  8.  
  9. % Digital Highpass Filter Specifications:
  10. wphp = 0.6*pi; % digital passband freq in rad
  11. wshp = 0.4586*pi; % digital stopband freq in rad
  12. Rp = 1; % passband ripple in dB
  13. As = 15; % stopband attenuation in dB
  14.  
  15. %[bhp, ahp] = butthpf(wphp, wshp, Rp, As)
  16. [bhp, ahp] = cheb1hpf(wphp, wshp, Rp, As)
  17. %[bhp, ahp] = cheb2hpf(wphp, wshp, Rp, As)
  18. %[bhp, ahp] = eliphpf(wphp, wshp, Rp, As)
  19. [C, B, A] = dir2cas(bhp, ahp);
  20.  
  21. % Calculation of Frequency Response:
  22. %[dblp, maglp, phalp, grdlp, wwlp] = freqz_m(blp, alp);
  23. [dbhp, maghp, phahp, grdhp, wwhp] = freqz_m(bhp, ahp);
  24.  
  25. delta_w = 2*pi/1000;
  26. Rp_hp = -(min(dbhp(ceil(wphp/delta_w+1):1:501))); % Actual Passband Ripple
  27.  
  28. fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp_hp);
  29.  
  30. As_hp = -round(max(dbhp(1:1:ceil(wshp/delta_w)+1))); % Min Stopband attenuation
  31. fprintf('\nMin Stopband attenuation is %.4f dB.\n\n', As_hp);
  32.  
  33. %% -----------------------------------------------------------------
  34. %% Plot
  35. %% -----------------------------------------------------------------
  36.  
  37. figure('NumberTitle', 'off', 'Name', 'Problem 8.34 Chebyshev-1 Highpass')
  38. set(gcf,'Color','white');
  39. M = 2; % Omega max
  40.  
  41. subplot(2,2,1); plot(wwhp/pi, maghp); axis([0, M, 0, 1.2]); grid on;
  42. xlabel('Digital frequency in \pi units'); ylabel('|H|'); title('Highpass Filter Magnitude Response');
  43. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, M]);
  44. set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.8913, 1]);
  45.  
  46. subplot(2,2,2); plot(wwhp/pi, dbhp); axis([0, M, -100, 2]); grid on;
  47. xlabel('Digital frequency in \pi units'); ylabel('Decibels'); title('Highpass Filter Magnitude in dB');
  48. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, 1.4, 1.5414, M]);
  49. set(gca, 'YTickMode', 'manual', 'YTick', [-80, -23, -10, -1, 0]);
  50. set(gca,'YTickLabelMode','manual','YTickLabel',['80'; '23'; '10';' 1';' 0']);
  51.  
  52. subplot(2,2,3); plot(wwhp/pi, phahp/pi); axis([0, M, -1.1, 1.1]); grid on;
  53. xlabel('Digital frequency in \pi nuits'); ylabel('radians in \pi units'); title('Highpass Filter Phase Response');
  54. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, M]);
  55. set(gca, 'YTickMode', 'manual', 'YTick', [-1:1:1]);
  56.  
  57. subplot(2,2,4); plot(wwhp/pi, grdhp); axis([0, M, 0, 15]); grid on;
  58. xlabel('Digital frequency in \pi units'); ylabel('Samples'); title('Highpass Filter Group Delay');
  59. set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, M]);
  60. set(gca, 'YTickMode', 'manual', 'YTick', [0:5:15]);
  61.  
  62. % -----------------------------------------------------
  63. % method 2
  64. % -----------------------------------------------------
  65. % Digital lowpass Filter Specifications:
  66. [wpLP, wsLP, alpha] = hp2lpfre(wphp, wshp);
  67.  
  68. prompt = 'Please input the type of digital lp filter: \n\n butter or cheby1 or cheby2 or ellip [butter]: ';
  69. type = input(prompt , 's');
  70.  
  71. [bhp, ahp] = dhpfd_bl(type, wphp, wshp, Rp, As)
  72.  
  73. [C, B, A] = dir2cas(bhp, ahp)

  运行结果:

cheb1hpf函数,得到Chebyshev-1型高通滤波器,系统函数直接形式的系数,阶数为4

直接形式转换成串联形式,系数

Chebyshev-1型高通滤波器,幅度谱、相位谱和群延迟响应

最小阻带衰减达到23dB,满足15dB的设计要求。

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

  1. 《DSP using MATLAB》Problem 5.34

    第1小题 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  2. 《DSP using MATLAB》Problem 7.34

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

  3. 《DSP using MATLAB》Problem 7.12

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

  4. 《DSP using MATLAB》Problem 7.35

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

  5. 《DSP using MATLAB》Problem 7.27

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

  6. 《DSP using MATLAB》Problem 7.26

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

  7. 《DSP using MATLAB》Problem 7.25

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

  8. 《DSP using MATLAB》Problem 7.24

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

  9. 《DSP using MATLAB》Problem 7.23

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

随机推荐

  1. Delphi 时间函数:关于时间精确的几个函数和方法

    //取毫秒级时间精度(方法一): var t1,t2:int64; r1:int64; begin t1:=GetTickCount;//获取开始计数 WINDOWS API sleep(1000); ...

  2. Python3 测试报告BeautifulReport中添加截图

    在测试类中,添加save_img方法,在测试过程中出现错误时,自动截图并返回失败 默认存放的图片路径是img def save_img(self, img_name): ""&qu ...

  3. Session监听类HttpSessionListener介绍及在listener里取得request

    Session监听类HttpSessionListener介绍及在listener里取得request servlet-api.jar中提供了监听类HttpSessionListener,主要方法有两 ...

  4. jQuery方法判断checkbox是否选中以及改变checkbox的选中状态

    jquery判断checked的三种方法: .attr('checked):   //看版本1.6+返回:”checked”或”undefined” ;1.5-返回:true或false .prop( ...

  5. pytorch处理模型过拟合

    演示代码如下 import torch from torch.autograd import Variable import torch.nn.functional as F import matpl ...

  6. HDU1285-确定比赛名次-拓扑排序板子题

    有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...

  7. UVA 12676 Inverting Huffman

    题目链接:https://vjudge.net/problem/UVA-12676 题目大意 一串文本中包含 N 个不同字母,经过哈夫曼编码后,得到这 N 个字母的相应编码长度,求文本的最短可能长度. ...

  8. Android笔记之Fragment中创建ViewModel的正确方式

    之前一直都是这么写的 pageViewModel = ViewModelProviders.of(this).get(PageViewModel.class); //参数this是当前fragment ...

  9. 错误Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/fs/FSDataInputStream排查思路

    spark1(默认CDH自带版本)不存在这个问题,主要是升级了spark2(CDHparcel升级)版本安装后需要依赖到spark1的旧配置去读取hadoop集群的依赖包. 1./etc/spark2 ...

  10. 判断APP是否已安装

    NSString *str = [NSString stringWithFormat:@"%@://%@",[dic objectForKey:@"ios_url_sch ...