《DSP using MATLAB》Problem 8.34
今天下了小雨,空气中泛起潮湿的味道,阴冷的感觉袭来,心情受到小小影响。
代码:
hp2lpfre子函数
function [wpLP, wsLP, alpha] = hp2lpfre(wphp, wshp)
% Band-edge frequency conversion from highpass to lowpass digital filter
% -------------------------------------------------------------------------
% [wpLP, wsLP, alpha] = hp2lpfre(wphp, wshp)
% wpLP = passband edge for the lowpass digital prototype
% wsLP = stopband edge for the lowpass digital prototype
% alpha = lowpass to highpass transformation parameter
% wphp = passband edge frequency for the highpass
% wshp = stopband edge frequency for the highpass
%
%
if wphp <= 0
error('Passband edge must be larger than 0.')
end if wshp >= wphp
error('Stopband edge must be smaller then Passband edge')
end % Determine the digital lowpass cutoff frequencies:
wpLP = 0.2*pi;
alpha = -(cos((wpLP + wphp)/2))/(cos((wpLP - wphp)/2));
wsLP = angle(-(exp(-j*wshp)+alpha)/(1+alpha*exp(-j*wshp)));
dhpfd_bl子函数
function [b, a] = dhpfd_bl(type, wp, ws, Rp, As)
% IIR Highpass Filter Design using bilinear transformation
% -----------------------------------------------------------------------
% [b, a] = dhpfd_bl(type, wp, ws, Rp, As);
% type = 'butter' or 'cheby1' or 'cheby2' or 'ellip'
% b = numerator polynomial coefficients of highpass filter , Direct form
% a = denominator polynomial coefficients of highpass 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
%
%
if isempty(type)
str = 'butter';
end switch type
case 'butter'
[b , a] = butthpf(wp, ws, Rp, As); break;
case 'cheby1'
[b , a] = cheb1hpf(wp, ws, Rp, As); break;
case 'cheby2'
[b , a] = cheb2hpf(wp, ws, Rp, As); break;
case 'ellip'
[b , a] = eliphpf(wp, ws, Rp, As); break;
otherwise
disp('Oh, input may be error!\n');
end
%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 8.34 \n\n'); banner();
%% ------------------------------------------------------------------------ % Digital Highpass Filter Specifications:
wphp = 0.6*pi; % digital passband freq in rad
wshp = 0.4586*pi; % digital stopband freq in rad
Rp = 1; % passband ripple in dB
As = 15; % stopband attenuation in dB %[bhp, ahp] = butthpf(wphp, wshp, Rp, As)
[bhp, ahp] = cheb1hpf(wphp, wshp, Rp, As)
%[bhp, ahp] = cheb2hpf(wphp, wshp, Rp, As)
%[bhp, ahp] = eliphpf(wphp, wshp, Rp, As)
[C, B, A] = dir2cas(bhp, ahp); % Calculation of Frequency Response:
%[dblp, maglp, phalp, grdlp, wwlp] = freqz_m(blp, alp);
[dbhp, maghp, phahp, grdhp, wwhp] = freqz_m(bhp, ahp); delta_w = 2*pi/1000;
Rp_hp = -(min(dbhp(ceil(wphp/delta_w+1):1:501))); % Actual Passband Ripple fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp_hp); As_hp = -round(max(dbhp(1:1:ceil(wshp/delta_w)+1))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n\n', As_hp); %% -----------------------------------------------------------------
%% Plot
%% ----------------------------------------------------------------- figure('NumberTitle', 'off', 'Name', 'Problem 8.34 Chebyshev-1 Highpass')
set(gcf,'Color','white');
M = 2; % Omega max subplot(2,2,1); plot(wwhp/pi, maghp); axis([0, M, 0, 1.2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('|H|'); title('Highpass Filter Magnitude Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.8913, 1]); subplot(2,2,2); plot(wwhp/pi, dbhp); axis([0, M, -100, 2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Decibels'); title('Highpass Filter Magnitude in dB');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, 1.4, 1.5414, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-80, -23, -10, -1, 0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['80'; '23'; '10';' 1';' 0']); subplot(2,2,3); plot(wwhp/pi, phahp/pi); axis([0, M, -1.1, 1.1]); grid on;
xlabel('Digital frequency in \pi nuits'); ylabel('radians in \pi units'); title('Highpass Filter Phase Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-1:1:1]); subplot(2,2,4); plot(wwhp/pi, grdhp); axis([0, M, 0, 15]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Samples'); title('Highpass Filter Group Delay');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.4586, 0.6, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0:5:15]); % -----------------------------------------------------
% method 2
% -----------------------------------------------------
% Digital lowpass Filter Specifications:
[wpLP, wsLP, alpha] = hp2lpfre(wphp, wshp); prompt = 'Please input the type of digital lp filter: \n\n butter or cheby1 or cheby2 or ellip [butter]: ';
type = input(prompt , 's'); [bhp, ahp] = dhpfd_bl(type, wphp, wshp, Rp, As) [C, B, A] = dir2cas(bhp, ahp)
运行结果:
cheb1hpf函数,得到Chebyshev-1型高通滤波器,系统函数直接形式的系数,阶数为4
直接形式转换成串联形式,系数
Chebyshev-1型高通滤波器,幅度谱、相位谱和群延迟响应
最小阻带衰减达到23dB,满足15dB的设计要求。
《DSP using MATLAB》Problem 8.34的更多相关文章
- 《DSP using MATLAB》Problem 5.34
第1小题 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.34
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.12
阻带衰减50dB,我们选Hamming窗 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 7.35
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《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 ...
随机推荐
- exports和module.exports的区别——学习笔记
一开始,exports和module.exports都指向空对象(同一内存块),exports是引用 module.exports的值.module.exports 被改变的时候,exports不会被 ...
- Python中的网络爬虫怎么用?
爬虫概述 (约2016年)网络爬虫个人使用和科研范畴基本不存在问题,但商业盈利范畴就要看对方了. 通过网站的Robots协议(爬虫协议)可以知道可以和不可以抓取的内容,其中User-Agent: 为允 ...
- java script两个列表之间移动数据
<select name="b1" id="hao" style="width:100px; height:200px;" size= ...
- 揭秘!2周实现上云上市,阿里云SaaS上云工具包如何打造新云梯?
提到“上云”,很多人会理解成上IaaS,比如买一些计算.存储和网络云产品,把自己的应用系统部署上去.这的确是通常意义的上云.但对SaaS而言,需要从产品.商业.服务,三个维度考虑SaaS伙伴和客户的痛 ...
- Android获取Root权限之后的静默安装实现代码示例分析
转:http://blog.csdn.net/jiankeufo/article/details/43795015 Adroid开发中,我们有时会遇到一些特殊功能的实现,有些功能并没有太高技术难度,但 ...
- 剑指offer——18打印从1到最大的n位数
题目: 输入数字n,按顺序打印出从1到最大的n位十进制数.比如输入3,则打印出1.2.3一直到最大的3位数999. 题解: 注意大数溢出问题,故使用字符串更靠谱 class Solution { pu ...
- Ulimit 文件配置
cat /etc/security/limits.confsudo vim /etc/security/limits.conf * hard nofile 999999 * soft nofile 9 ...
- pyhton2与python3的使用区别
刚刚开始学习python这门编程语言,考虑到python不同版本的一些用法不同,收集整理了一份python2与python3之间的区别,目前可能不全 编码(核心类) Python2默认编码ascii, ...
- uoj139 【UER #4】被删除的黑白树
题目 不难发现有一个暴力\(dp\) 设\(dp[x][l]\)表示\(x\)点子树内所有叶子节点到\(x\)的路径上都有\(l\)和黑点时最多能染多个黑点 转移就是 \[dp[x][l]=\max( ...
- javascript面向对象编程笔记(函数之闭包)
3 函数 3.5 闭包(closures) 3.5.1 作用域链 与很多程序设计语言不同,javascript不存在大括号级的作用域,但它有函数作用域,即在函数内定义的变量在函数外是不可见的.但如果该 ...