《DSP using MATLAB》Problem 8.36
上代码:
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的更多相关文章
- 《DSP using MATLAB》Problem 5.36
第1小题 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.36
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 4.15
只会做前两个, 代码: %% ---------------------------------------------------------------------------- %% Outpu ...
- 《DSP using MATLAB》Problem 7.27
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.26
注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.25
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.24
又到清明时节,…… 注意:带阻滤波器不能用第2类线性相位滤波器实现,我们采用第1类,长度为基数,选M=61 代码: %% +++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.23
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info a ...
- 《DSP using MATLAB》Problem 7.16
使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- 28. string类中方法练习
1. 自己写trim方法 public class Demo3 { public static void main(String[] args) { System.out.println(myTrim ...
- linux命令系列-tar(打包压缩)
tar命令可以为linux的文件和目录创建档案.利用tar命令,可以把一大堆的文件和目录全部打包成一个文件,这对于备份文件或将几个文件组合成为一个文件以便于网络传输是非常有用的. 首先要弄清两个概念: ...
- Web API 接口参考
Web API 接口参考:https://developer.mozilla.org/zh-CN/docs/Web/API
- 1、Go语言的介绍
一.概念 Go语言(Golang)是云计算时代的C语言,使用Go编译的程序可以媲美C/C++代码的速度,而且更加安全.支持并行进程. 二.Go语言的优势 1.部署简单.可以直接编译成机器码,不依赖其他 ...
- 【RabbitMQ】六种模式与SpringBoot整合
添加rabbitmq的依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifac ...
- Cucumber:启动类配置
Cucumber:启动类配置 package com.steps; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cuc ...
- NX二次开发-调系统命令UF_load_library[UFUN调DLL]
此函数可以调DLL,可以调宏,当然也可以调其他内部函数(知道哪个内部函数怎么用的前提下). #include <uf.h> void UFUN_API_Call_DLL(char* dll ...
- 简单实用的makefile
简单的makefile 为了说明问题,就新建一组文件如下: 文件布局及运行结果: make clean 按目录归置 文件看起来是是清楚了,但是makefile写得揪心. 实用版 (1)Makefile ...
- 2019 牛客多校第三场 B Crazy Binary String
题目链接:https://ac.nowcoder.com/acm/contest/883/B 题目大意 给定一个长度为 N 的 01 字符串,输出最长子串和子序列的长度,满足其中 0 和 1 的个 ...
- LeetCode刷题笔记-回溯法-括号生成
题目描述: 给出 n 代表生成括号的对数,请你写出一个函数,使其能够生成所有可能的并且有效的括号组合. 例如,给出 n = 3,生成结果为: [ "((()))", "( ...