《DSP using MATLAB》Problem 8.33
代码:
%% ------------------------------------------------------------------------
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 8.33.2 \n\n'); banner();
%% ------------------------------------------------------------------------ % Digital Filter Specifications:
wp = 0.45*pi; % digital passband freq in rad
ws = 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 % Analog prototype specifications: Inverse Mapping for frequencies
T = 1; % set T = 1
Fs = 1/T;
OmegaP = (2/T)*tan(wp/2); % Prewarp(Cutoff) prototype passband freq
OmegaS = (2/T)*tan(ws/2); % Prewarp(cutoff) prototype stopband freq OmegaP/pi
OmegaS/pi % ---------------------------------------------------------------
% method 1: afd_chb1 function
% ---------------------------------------------------------------
% Analog Chebyshev-1 Prototype Filter Calculation:
[cs, ds] = afd_chb1(OmegaP, OmegaS, Rp, As); % Calculation of second-order sections:
fprintf('\n***** Cascade-form in s-plane: START *****\n');
[CS, BS, AS] = sdir2cas(cs, ds);
fprintf('\n***** Cascade-form in s-plane: END *****\n'); % Calculation of Frequency Response:
[db_s, mag_s, pha_s, ww_s] = freqs_m(cs, ds, pi/T); delta_w = 2*pi/1000;
Rp_s = -(min(db_s(501:1:floor(OmegaP/delta_w)+501))); % Actual Passband Ripple fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp_s); As_s = -round(max(db_s(floor(OmegaS/delta_w)+501:1:1000))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As_s); % Calculation of Impulse Response:
[ha, x, t] = impulse(cs, ds); % Impulse Invariance Transformation:
%[b, a] = imp_invr(cs, ds, T); % Bilinear Transformation
[b, a] = bilinear(cs, ds, 1/T);
[C, B, A] = dir2cas(b, a); % Calculation of Frequency Response:
[db, mag, pha, grd, ww] = freqz_m(b, a); delta_w = 2*pi/1000;
Rp = -(min(db(1:1:ceil(wp/delta_w)+1))); % Actual Passband Ripple fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(ceil(ws/delta_w)+1:1:501))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); %% -----------------------------------------------------------------
%% Plot
%% -----------------------------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 8.33.2 Analog Chebyshev-1 lowpass')
set(gcf,'Color','white');
M = 1; % Omega max subplot(2,2,1); plot(ww_s/pi, mag_s); grid on; %axis([-M, M, 0, 1.2]);
xlabel(' Analog frequency in \pi units'); ylabel('|H|'); title('Magnitude in Absolute');
set(gca, 'XTickMode', 'manual', 'XTick', [-0.6366, -0.5437, 0, 0.5437, 0.6366]);
set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.001, 0.5, 0.9441, 1]); subplot(2,2,2); plot(ww_s/pi, db_s); grid on; %axis([0, M, -50, 10]);
xlabel('Analog frequency in \pi units'); ylabel('Decibels'); title('Magnitude in dB ');
set(gca, 'XTickMode', 'manual', 'XTick', [-0.6366, -0.5437, 0, 0.5437, 0.6366]);
set(gca, 'YTickMode', 'manual', 'YTick', [-65, -60, -1, 0]);
set(gca,'YTickLabelMode','manual','YTickLabel',[ '65'; '60';'1 ';' 0']); subplot(2,2,3); plot(ww_s/pi, pha_s/pi); grid on; axis([-M, M, -1.2, 1.2]);
xlabel('Analog frequency in \pi nuits'); ylabel('radians'); title('Phase Response');
set(gca, 'XTickMode', 'manual', 'XTick', [-0.6366, -0.5437, 0, 0.5437, 0.6366]);
set(gca, 'YTickMode', 'manual', 'YTick', [-1:0.5:1]); subplot(2,2,4); plot(t, ha); grid on; %axis([0, 30, -0.05, 0.25]);
xlabel('time in seconds'); ylabel('ha(t)'); title('Impulse Response'); figure('NumberTitle', 'off', 'Name', 'Problem 8.33.2 Digital Chebyshev-1 lowpass by afd_chb1 function')
set(gcf,'Color','white');
M = 2; % Omega max subplot(2,2,1); plot(ww/pi, mag); axis([0, M, 0, 1.2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('|H|'); title('Magnitude Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.50, 1.0, 1.5, 1.55, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.001, 0.5, 0.9441, 1]); subplot(2,2,2); plot(ww/pi, pha/pi); axis([0, M, -1.1, 1.1]); grid on;
xlabel('Digital frequency in \pi nuits'); ylabel('radians in \pi units'); title('Phase Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.50, 1.0, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-1:1:1]); subplot(2,2,3); plot(ww/pi, db); axis([0, M, -100, 10]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Decibels'); title('Magnitude in dB ');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.50, 1.0, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-65, -60, -1, 0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['65'; '60';' 1';' 0']); subplot(2,2,4); plot(ww/pi, grd); grid on; axis([0, M, 0, 200]);
xlabel('Digital frequency in \pi units'); ylabel('Samples'); title('Group Delay');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.50, 1.0, M]);
%set(gca, 'YTickMode', 'manual', 'YTick', [0:20:100]); figure('NumberTitle', 'off', 'Name', 'Problem 8.33.2 Pole-Zero Plot')
set(gcf,'Color','white');
zplane(b,a);
title(sprintf('Pole-Zero Plot'));
%pzplotz(b,a); % ---------------------------------------------------------------
% method 2: MATLAB cheby1 function
% --------------------------------------------------------------- % Analog Prototype Order Calculations:
ep = sqrt(10^(Rp/10)-1); % Passband Ripple Factor
A = 10^(As/20); % Stopband Attenuation Factor
OmegaC = OmegaP; % Analog Chebyshev-1 prototype cutoff freq
OmegaR = OmegaS/OmegaP; % Analog prototype Transition ratio
g = sqrt(A*A-1)/ep; % Analog prototype Intermediate cal N = ceil(log10(g+sqrt(g*g-1))/log10(OmegaR+sqrt(OmegaR*OmegaR-1)));
fprintf('\n\n ********** Chebyshev-I Filter Order = %3.0f \n', N) % Digital Chebyshev-1 Filter Design:
wn = wp/pi; % Digital Chebyshev-1 cutoff freq in pi units [b, a] = cheby1(N, Rp, wn); [C, B, A] = dir2cas(b, a) % Calculation of Frequency Response:
[db, mag, pha, grd, ww] = freqz_m(b, a); delta_w = 2*pi/1000;
Rp = -(min(db(1:1:ceil(wp/delta_w)+1))); % Actual Passband Ripple fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(ceil(ws/delta_w)+1:1:501))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); %% -----------------------------------------------------------------
%% Plot
%% ----------------------------------------------------------------- figure('NumberTitle', 'off', 'Name', 'Problem 8.33.2 Digital Chebyshev-1 lowpass by cheby1 function')
set(gcf,'Color','white');
M = 2; % Omega max subplot(2,2,1); plot(ww/pi, mag); axis([0, M, 0, 1.2]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('|H|'); title('Magnitude Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.50, 1, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.001, 0.9441, 1]); subplot(2,2,2); plot(ww/pi, pha/pi); axis([0, M, -1.1, 1.1]); grid on;
xlabel('Digital frequency in \pi nuits'); ylabel('radians in \pi units'); title('Phase Response');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.50, 1, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-1:1:1]); subplot(2,2,3); plot(ww/pi, db); axis([0, M, -100, 10]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Decibels'); title('Magnitude in dB ');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.50, 1, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [-70, -60, -15, -1, 0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['70'; '60';'15';' 1';' 0']); subplot(2,2,4); plot(ww/pi, grd); axis([0, M, 0, 150]); grid on;
xlabel('Digital frequency in \pi units'); ylabel('Samples'); title('Group Delay');
set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.45, 0.50, 1, M]);
set(gca, 'YTickMode', 'manual', 'YTick', [0:20:100]); % ----------------------------------------------
% Calculation of Impulse Response
% ----------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 8.33.2 Imp & Freq Response')
set(gcf,'Color','white');
t = [0:0.5:160]; subplot(2,1,1); impulse(cs,ds,t); grid on; % Impulse response of the analog filter
axis([0,160,-0.4,0.5]);hold on n = [0:1:160/T]; hn = filter(b,a,impseq(0,0,160/T)); % Impulse response of the digital filter
stem(n*T,hn); xlabel('time in sec'); title (sprintf('Impulse Responses, T=%f',T));
hold off % Calculation of Frequency Response:
[dbs, mags, phas, wws] = freqs_m(cs, ds, 2*pi/T); % Analog frequency s-domain [dbz, magz, phaz, grdz, wwz] = freqz_m(b, a); % Digital z-domain %% -----------------------------------------------------------------
%% Plot
%% ----------------------------------------------------------------- subplot(2,1,2); plot(wws/(2*pi), mags*Fs, 'b', wwz/(2*pi)*Fs, magz,'r'); grid on; xlabel('frequency in Hz'); title('Magnitude Responses'); ylabel('Magnitude'); text(-0.3,0.15,'Analog filter', 'Color', 'b'); text(0.4,0.55,'Digital filter', 'Color', 'r');
运行结果:
这里只放chebyshev-1型,第2小题
通带、阻带绝对指标,以及模拟滤波器频带截止频率,
模拟chebyshev-1型低通滤波器,幅度谱、相位谱和脉冲响应
采用afd_chb1函数(双线性变换法),得到数字chebyshev-1低通滤波器,其幅度谱、相位谱和群延迟响应
采用MATLAB自带cheby1函数,得到数字低通,幅度谱、相位谱和群延迟响应
以下三图是模拟低通、两函数得到数字低通,各自最低阻带衰减对比,可见,MATLAB自带的cheby1函数设计的数字低通可以达到70dB。
至于其它的代码这里不放了,步骤类似,最后给出设计滤波器阶数和阻带衰减对比结果
《DSP using MATLAB》Problem 8.33的更多相关文章
- 《DSP using MATLAB》Problem 7.33
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.36
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.29
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% 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 ...
- 《DSP using MATLAB》Problem 7.16
使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- java zxing 生成条形码和二维吗
依赖 <dependency> <groupId>com.google.zxing</groupId> <artifactId>core</art ...
- 【NOI2019模拟2019.7.1】三格骨牌(轮廓线dp转杨图上钩子定理)
Description \(n,m<=1e4,mod ~1e9+7\) 题解: 显然右边那个图形只有旋转90°和270°后才能放置. 先考虑一个暴力的轮廓线dp: 假设已经放了编号前i的骨牌,那 ...
- struts之ActionServlet
ActionServlet类是Struts框架的内置核心控制器组件,它继承了javax. servlet.http.HttpServlet类,Struts的启动一般从加载ActionServlet开始 ...
- QString与string的相互转换【转载】
文章转载自https://blog.csdn.net/qq_33485434/article/details/80680506 1.QString转换String string s = qstr.to ...
- 在vs2010下编译boost
1. 解压缩后,运行bootstrap.bat批处理文件,得到bjam.exe; 2. 在vs2010下编译boost boost最新版本已经支持vs2010,然而直接下载编译会发现一堆bug: 首先 ...
- CocoaPods管理iOS项目 2018年11月06日
一.创建Test工程项目 二.打开终端 当前pod版本(1.6.0.beta.2最新版本2018年11月06日)和gem源路径(https://gems.ruby-china.com): 1.cd+当 ...
- arr = map(float,arr)输出问题
代码: arr = ['22','44','66','88']arr = map(float,arr)print(arr) 输出: <map object at 0x000001B48C30EE ...
- linux下链接时缺少动态链接库
1, 用ln将需要的so文件链接到/usr/lib或者/lib这两个默认的目录下边 ln -s /where/you/install/lib/*.so /usr/libsudo ldconfig 2, ...
- licecap图片区域问题
之前一直好用的licecap最近突然没法用了,结果发现是屏幕分辨率的文本大小的问题,因为选了特大的.发现制作成的gif图片的区域有问题.后来改回中等的,就可以了.
- RDLC报表问题:尚未指定报表“Report1”的报表定义
原文:尚未指定报表“Report1”的报表定义 在做RDLC项目中遇到这样的错误 本地报表处理期间出错. 尚未指定报表“Report1”的报表定义 未将对象引用设置到对象的实例. 解决方案: 打开re ...