上代码:

function [wpLP, wsLP, alpha] = lp2lpfre(wplp, wslp)
% Band-edge frequency conversion from lowpass to lowpass digital filter
% -------------------------------------------------------------------------
% [wpLP, wsLP, alpha] = lp2lpfre(wplp, wslp)
% wpLP = passband edge for the lowpass digital prototype
% wsLP = stopband edge for the lowpass digital prototype
% alpha = lowpass to lowpass transformation parameter
% wplp = passband edge frequency for the given lowpass
% wslp = stopband edge frequency for the given lowpass
%
%
if wplp <= 0
error('Passband edge must be larger than 0.')
end if wslp <= wplp
error('Stopband edge must be larger then Passband edge')
end % Determine the digital lowpass cutoff frequencies:
wpLP = 0.2*pi;
alpha = sin((wpLP - wplp)/2)/sin((wpLP + wplp)/2);
wsLP = -angle((exp(-j*wslp)-alpha)/(1-alpha*exp(-j*wslp)));

  

function [b, a] = dlpfd_bl(type, wp, ws, Rp, As)
% IIR Lowpass Filter Design using bilinear transformation
% -----------------------------------------------------------------------
% [b, a] = dlpfd_bl(type, wp, ws, Rp, As);
% type = 'butter' or 'cheby1' or 'cheby2' or 'ellip'
% b = numerator polynomial coefficients of lowpass filter , Direct form
% a = denominator polynomial coefficients of lowpass filter, Direct form
% wp = Passband edge frequency in radians;
% ws = Stopband edge frequency in radians (wp < ws);
% Rp = Passband ripple in +dB; Rp > 0
% As = Stopband attenuation in +dB; As > 0
%
%
%prompt = 'Please input the type of digital lp filter: butter or cheby1 or cheby2 or ellip [butter] ';
%type = input(prompt , 's'); if isempty(type)
str = 'butter';
end switch type
case 'butter'
[b , a] = buttlpf(wp, ws, Rp, As);
case 'cheby1'
[b , a] = cheb1lpf(wp, ws, Rp, As);
case 'cheby2'
[b , a] = cheb2lpf(wp, ws, Rp, As);
case 'ellip'
[b , a] = eliplpf(wp, ws, Rp, As);
otherwise
disp('Oh, input may be error!');
end

  第1小题

%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 8.36.1 \n\n'); banner();
%% ------------------------------------------------------------------------ % Digital lowpass Filter Specifications:
wplp = 0.45*pi; % digital passband freq in rad
wslp = 0.50*pi; % digital stopband freq in rad
Rp = 0.5; % passband ripple in dB
As = 60; % stopband attenuation in dB Ripple = 10 ^ (-Rp/20) % passband ripple in absolute
Attn = 10 ^ (-As/20) % stopband attenuation in absolute fprintf('\n*******Digital lowpass, Coefficients of DIRECT-form***********\n');
[blp, alp] = buttlpf(wplp, wslp, Rp, As)
%[blp, alp] = cheb1lpf(wphp, wshp, Rp, As)
%[blp, alp] = cheb2lpf(wphp, wshp, Rp, As)
%[blp, alp] = eliplpf(wphp, wshp, Rp, As)
[C, B, A] = dir2cas(blp, alp) % Calculation of Frequency Response:
[dblp, maglp, phalp, grdlp, wwlp] = freqz_m(blp, alp);
%[dbhp, maghp, phahp, grdhp, wwhp] = freqz_m(bhp, ahp); % ---------------------------------------------------------------
% find Actual Passband Ripple and Min Stopband attenuation
% ---------------------------------------------------------------
delta_w = 2*pi/1000;
Rp_lp = -(min(dblp(1:1:ceil(wplp/delta_w)+1))); % Actual Passband Ripple fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp_lp); As_lp = -round(max(dblp(ceil(wslp/delta_w)+1:1:501))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n\n', As_lp); %% -----------------------------------------------------------------
%% Plot
%% ----------------------------------------------------------------- figure('NumberTitle', 'off', 'Name', 'Problem 8.36.1 Butterworth lowpass by buttlpf function')
set(gcf,'Color','white');
M = 2; % Omega max subplot(2,2,1); plot(wwlp/pi, maglp); axis([0, M, 0, 1.2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('|H|'); title('Lowpass Filter Magnitude Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.9441, 1]); subplot(2,2,2); plot(wwlp/pi, dblp); axis([0, M, -150, 1]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Decibels'); title('Lowpass Filter Magnitude in dB');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [ -111, -85, -1, 0]);
%set(gca,'YTickLabelMode','manual','YTickLabel',['111'; '85'; '1 ';' 0']); subplot(2,2,3); plot(wwlp/pi, phalp/pi); axis([0, M, -1.1, 1.1]); grid on;
xlabel('Digital frequency in \pi nuits'); ylabel('radians in \pi units'); title('Lowpass Filter Phase Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-1:1:1]); subplot(2,2,4); plot(wwlp/pi, grdlp); axis([0, M, 0, 20]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Samples'); title('Lowpass Filter Group Delay');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0:10:20]); % -----------------------------------------------------
% method 2
% -----------------------------------------------------
% Digital lowpass Filter Specifications:
[wpLP, wsLP, alpha] = lp2lpfre(wplp, wslp); prompt = '\nPlease input the type of digital lp filter: \n\n butter or cheby1 or cheby2 or ellip [butter]: ';
type = input(prompt , 's'); [blp, alp] = dlpfd_bl(type, wplp, wslp, Rp, As); [C, B, A] = dir2cas(blp, alp); % -----------------------------------------------------
% method 3 butter function
% -----------------------------------------------------
% Calculation of Butterworth lp filter parameters:
[N, wn] = buttord(wplp/pi, wslp/pi, Rp, As) % Digital Butterworth lowpass Filter Design:
[blp, alp] = butter(N, wn, 'low') [C, B, A] = dir2cas(blp, alp) % Calculation of Frequency Response:
[dblp, maglp, phalp, grdlp, wwlp] = freqz_m(blp, alp);
%[dbhp, maghp, phahp, grdhp, wwhp] = freqz_m(bhp, ahp); % ---------------------------------------------------------------
% find Actual Passband Ripple and Min Stopband attenuation
% ---------------------------------------------------------------
delta_w = 2*pi/1000;
Rp_lp = -(min(dblp(ceil(1:1:wplp/delta_w+1)))); % Actual Passband Ripple fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp_lp); As_lp = -round(max(dblp(ceil(wslp/delta_w)+1 :1 : 501))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n\n', As_lp); %% -----------------------------------------------------------------
%% Plot
%% ----------------------------------------------------------------- figure('NumberTitle', 'off', 'Name', 'Problem 8.36.1 Butterworth lowpass by butter function')
set(gcf,'Color','white');
M = 1; % Omega max subplot(2,2,1); plot(wwlp/pi, maglp); axis([0, M, 0, 1.2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('|H|'); title('Lowpass Filter Magnitude Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.9441, 1]); subplot(2,2,2); plot(wwlp/pi, dblp); axis([0, M, -100, 2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Decibels'); title('Lowpass Filter Magnitude in dB');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-70, -60, -1, 0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['70'; '60';'1 ';' 0']); subplot(2,2,3); plot(wwlp/pi, phalp/pi); axis([0, M, -1.1, 1.1]); grid on;
xlabel('Digital frequency in \pi nuits'); ylabel('radians in \pi units'); title('Lowpass Filter Phase Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-1:1:1]); subplot(2,2,4); plot(wwlp/pi, grdlp); axis([0, M, 0, 90]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Samples'); title('Lowpass Filter Group Delay');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.5, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0:10:90]);

  运行结果:

绝对指标

数字低通,频带边界截止频率

采用buttlpf函数,数字低通butterworth滤波器阶数51,系统函数直接形式系数

转换成串联形式,系数

采用butter(MATLAB自带函数),计算数字低通滤波器,阶数51

可见自带函数比个人所写的效果强!

第3小题,Chebyshev-2型

采用cheb2lpf函数,得到的Chebyshev-2型数字低通滤波器,幅度谱、相位谱和群延迟响应

采用cheby2(MATLAB自带函数),计算得到数字低通滤波器,系统函数串联形式系数

Chebyshev-1型和Elliptic型数字低通,这里不放图了。

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

  1. 《DSP using MATLAB》Problem 5.36

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

  2. 《DSP using MATLAB》Problem 7.36

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

  3. 《DSP using MATLAB》Problem 4.15

    只会做前两个, 代码: %% ---------------------------------------------------------------------------- %% Outpu ...

  4. 《DSP using MATLAB》Problem 7.27

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

  5. 《DSP using MATLAB》Problem 7.26

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

  6. 《DSP using MATLAB》Problem 7.25

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

  7. 《DSP using MATLAB》Problem 7.24

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

  8. 《DSP using MATLAB》Problem 7.23

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

  9. 《DSP using MATLAB》Problem 7.16

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

随机推荐

  1. xpath总结

    Python包 pip install lxml 在 XPath 中,有七种类型的节点:元素.属性.文本.命名空间.处理指令.注释以及文档(根)节点.XML 文档是被作为节点树来对待的. xpath语 ...

  2. 5432. 【NOIP2017提高A组集训10.28】三元组

    题目 题目大意 给你\(X+Y+Z\)个三元组\((x_i,y_i,z_i)\). 然后选\(X\)个\(x_i\),选\(Y\)个\(y_i\),选\(Z\)个\(z_i\). 每个三元组只能选择其 ...

  3. js面向对象的几种方式----工厂模式、构造函数模式、原型模式

    对象的字面量 var obj={} 创建实例对象 var obj=new Object() 工厂模式 function cPerson(name,sex,age){ var o = new Objec ...

  4. 一张图看懂阿里云网络产品【十五】IPv6 解决方案

    摘要: 作为国内首家全面支持IPv6的云厂商,阿里云12月再次推出全栈IPv6解决方案,核心产品已全面支持,协助客户小时/天级即可完成IPv6 访问.方案成功历经优酷.淘宝.天猫.双十一考验.SLB ...

  5. 解析Tomcat之HttpServlet详解

    解析Tomcat之HttpServlet详解 Servlet的框架是 由两个Java包组成:javax.servlet和javax.servlet.http. 在javax.servlet包中定义了所 ...

  6. mysql 导出导入数据 -csv

    MySql数据库导出csv文件命令: mysql> select first_name,last_name,email from account into outfile 'e://output ...

  7. [17]APUE:线程

    通常情况下,线程模型的并发性能优于进程模型,但不总是这样 线程的优势: 线程的创建.销毁及上下文切换代价比进程低 某些情况下,使用线程可以简化逻辑,避免异步编程的复杂性 同一进程内所有线程共享全局内存 ...

  8. 剑指offer——15剪绳子

    题目描述 给你一根长度为n的绳子,请把绳子剪成m段(m.n都是整数,n>1并且m>1),每段绳子的长度记为k[0],k[1],...,k[m].请问k[0]xk[1]x...xk[m]可能 ...

  9. 网络安全系列 之 TLS/SSL基本原理

    1. TLS/SSL基本工作方式: TLS/SSL的功能实现主要依赖于三类基本算法(参见"网络安全系列 之 密码算法"): 非对称加密算法:实现身份认证和密钥协商 对称加密算法: ...

  10. NodeJS学习笔记之Connect中间件模块(二)

    一,开篇分析 大家好,今天这篇文章主要是对"Connect"中间件以及相关辅助中间件,做一个源码分析系列,我想上一篇文章大家也看了, 介绍了使用方式及用途,而这篇也是出于本人的兴趣 ...