代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.37 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ w1 = 0; w2 = 0.30*pi; delta1 = 0.05; gain1 = 0.95;
w3 = 0.35*pi; w4 = 0.50*pi; delta2 = 0.10; gain2 = 2.00;
w5 = 0.55*pi; w6 = 0.75*pi; delta3 = 0.05; gain3 = 3.05;
w7 = 0.80*pi; w8 = pi; delta4 = 0.05; gain4 = 4.05; f = [w2, w3, w4, w5, w6, w7]/pi; m = [1, 1, 1, 1]; delta = [delta1, delta2, delta3, delta4]; [N, f0, m0, weights] = firpmord(f, m, delta);
fprintf('\n-------------------------------------------\n');
fprintf('\n Results by firpmord function:\n');
N
%f0
%m0
%weights
fprintf('\n-------------------------------------------\n'); weights = [delta2/delta1 1 delta2/delta3 delta2/delta4]
deltaH = max([delta1,delta2,delta3,delta4]); deltaL = min([delta1,delta2,delta3,delta4]); %Dw1 = min((w3-w2), (w5-w4));
%Dw2 = min((w5-w4), (w7-w6));
%Dw = min(Dw1, Dw2);
%M = ceil((-20*log10((delta1*delta2*delta3*delta4)^(1/4)) - 13) / (2.285*Dw) + 1) f = [ 0 w2 w3 w4 w5 w6 w7 pi]/pi;
m = [ 0.95 0.95 2 2 3.05 3.05 4.05 4.05]; h = firpm(N, f, m, weights); % even-number order
M = N+1
delta_w = 2*pi/1000;
[db, mag, pha, grd, w] = freqz_m(h, [1]); w1i = floor(w1/delta_w)+1; w2i = floor(w2/delta_w)+1;
w3i = floor(w3/delta_w)+1; w4i = floor(w4/delta_w)+1;
w5i = floor(w5/delta_w)+1; w6i = floor(w6/delta_w)+1;
w7i = floor(w7/delta_w)+1; w8i = floor(w8/delta_w)+1; Asd1 = -max(db(w1i:w2i))
%Asd2 = -max(db(w3i:w4i))
%Asd3 = -max(db(w5i:w6i))
%Asd4 = -max(db(w7i:w8i)) %[Hr, ww, a, L] = Hr_Type1(h);
[Hr,omega,P,L] = ampl_res(h);
l = 0:M-1; %% -------------------------------------------------
%% Plot
%% ------------------------------------------------- figure('NumberTitle', 'off', 'Name', 'Problem 7.37')
set(gcf,'Color','white'); subplot(2,2,1); stem(l, h); axis([-1, M, -1.0, 2.4]); grid on;
xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response, M=45');
set(gca,'XTickMode','manual','XTick',[0,(M-1)/2,M-1])
set(gca,'YTickMode','manual','YTick',[-1.0:0.4:2.4]) subplot(2,2,2); plot(w/pi, db); axis([0, 1, -20, 10]); grid on;
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB ');
set(gca,'XTickMode','manual','XTick',f)
set(gca,'YTickMode','manual','YTick',[-20,-12,-5,-2,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['20';'12';' 5';' 2';' 0']); subplot(2,2,3); plot(omega/pi, Hr); axis([0, 1, -0.2, 4.5]); grid on;
xlabel('frequency in \pi nuits'); ylabel('Hr(\omega)'); title('Amplitude Response');
set(gca,'XTickMode','manual','XTick',f)
set(gca,'YTickMode','manual','YTick',[0.9,1.0,1.9,2.1,3.0,3.1,4.0,4.1]); delta_w = 2*pi/1000; subplot(2,2,4); axis([0, 1, -deltaH, deltaH]);
b1w = omega(w1i:w2i)/pi; b1e = (Hr(w1i:w2i)-m(1)); %b1e = (Hr(w1i:w2i)-m(1))*weights(1);
b2w = omega(w3i:w4i)/pi; b2e = (Hr(w3i:w4i)-m(3)); %b2e = (Hr(w3i:w4i)-m(3))*weights(2);
b3w = omega(w5i:w6i)/pi; b3e = (Hr(w5i:w6i)-m(5)); %b3e = (Hr(w5i:w6i)-m(5))*weights(3);
b4w = omega(w7i:w8i)/pi; b4e = (Hr(w7i:w8i)-m(7)); %b4e = (Hr(w7i:w8i)-m(7))*weights(4); plot(b1w,b1e,b2w,b2e,b3w,b3e,b4w,b4e); grid on;
xlabel('frequency in \pi units'); ylabel('Hr(w)'); title('Error Response'); %title('Weighted Error');
set(gca,'XTickMode','manual','XTick',f);
set(gca,'YTickMode','manual','YTick',[-deltaH,0,deltaH]); figure('NumberTitle', 'off', 'Name', 'Problem 7.37 AmpRes of h(n), Parks-McClellan Method')
set(gcf,'Color','white'); plot(omega/pi, Hr); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Hr(\omega)'); title('Amplitude Response');
set(gca,'YTickMode','manual','YTick',[0.9,1.0,1.9,2.1,3.0,3.1,4.0,4.1]);
set(gca,'XTickMode','manual','XTick',f);

  运行结果:

先用firpmord求出N、f、m、weights,这些参数作为firpm函数参数,再求出脉冲响应序列

求出脉冲响应序列的幅度谱、误差响应函数

振幅谱,按照题目要求画了网格线

依前面经验,Parks-McClellan方法要比窗函数法、频率采样法设计的滤波器长度小,节约硬件资源,这里没有证明,以后有时间再算吧。

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

  1. 《DSP using MATLAB》Problem 5.37

    证明过程: 代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  2. 《DSP using MATLAB》Problem 8.37

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

  3. 《DSP using MATLAB》Problem 8.32

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

  4. 《DSP using MATLAB》Problem 7.36

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% 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. 使用SpringBoot1.4.0的一个坑

    时隔半年,再次使用Spring Boot快速搭建微服务,半年前使用的版本是1.2.5,如今看官网最新的release版本是1.4.0,那就用最新的来构建,由于部署环境可能有多套所以使用maven-fi ...

  2. C#中,用户控件UserControl里面用Panl加载UserControl,并实现利用委托互相传值

    用户控件主窗体结构:左侧树形菜单,右侧Panl: 根据点击的菜单节点,panl里面选择性加载某一个子窗体用户控件,并传值给子窗体: 反之,在子窗体进行相应的操作之后,传值给主窗体,触发主窗体的刷新. ...

  3. PyQt6的在线安装与环境配置

    https://www.jianshu.com/p/185e277e0058 一,安装好Python,Pycharm 二,安装或更新pip C:\> python -m pip install ...

  4. 关于OpenLiveWriter出错的修补方法

    OpenLiveWriter使用一段时间后可能会打不开,提示错误如下: 这是只需要把电脑的.net更新到4.6以上版本就可以了.

  5. thinkphp 控制器定义

    控制器和操作 一般来说,ThinkPHP的控制器是一个类,而操作则是控制器类的一个公共方法. 下面就是一个典型的控制器类的定义: <?php namespace Home\Controller; ...

  6. duilib教程之duilib入门简明教程10.界面设计器 DuiDesigner

    上一个教程讲解了怎么布局最大化.最小化.关闭按钮,但是如果手动去计算这三个按钮的位置和大小的话,非常的不直观,也很不方便.    所以这一章准备介绍duilib的UI设计器,由于这个设计器很不完善,也 ...

  7. 20175323《Java程序设计》第三周学习总结

    教材学习内容总结 这周开始用幕布记录学习过程和思路,下面是我这章的知识框架总结https://mubu.com/doc/aNMW9Clym0 教材学习中的问题和解决过程 问题1:教材90页的Trian ...

  8. Linux课程---16、apache虚拟主机设置(如何在一台服务器上配置三个域名)

    Linux课程---16.apache虚拟主机设置(如何在一台服务器上配置三个域名) 一.总结 一句话总结:有三个网站www.lampym.com,bbs.lampym.com,mysql.lampy ...

  9. 搞大数据,你不懂这三大数据处理趋势就OUT了

    搞大数据,你不懂这三大数据处理趋势就OUT了 企业数据每年以PB级甚至上百PB爆炸式增长,越来越大的数据量正为扩大分析策略在企业应用软件领域的拓展提供了数据基础,但数据的价值是有时效性的,越早分析越能 ...

  10. 使用串口绘制实时曲线 —— SerialChart

    SerialChart:下载 1. 实验效果 2. 串口程序 ){ ){ y = ; x = ; } ) y++; else y--; z = sin(x*Pi/); p = cos(x*Pi/); ...