代码:

%% ------------------------------------------------------------------------
%% 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的更多相关文章

  1. 《DSP using MATLAB》Problem 7.33

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

  2. 《DSP using MATLAB》Problem 7.36

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

  3. 《DSP using MATLAB》Problem 7.29

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

  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. Python 刷题知识点

    if : elif : else : print('{0} \n{1} \n{2}' .format((a + b), (a - b), (a * b))) print(*[num**2 for nu ...

  2. SpringMVC 拦截器原理

    前言 SpringMVC 拦截器也是Aop(面向切面)思想构建,但不是 Spring Aop 动态代理实现的, 主要采用责任链和适配器的设计模式来实现,直接嵌入到 SpringMVC 入口代码里面. ...

  3. NX-二次开发创建圆弧(三点圆弧)UF_CURVE_create_arc_3point

    NX9+VS2012 #include <uf.h> #include <uf_curve.h> UF_initialize(); //起点 ]; ArcStartPoint[ ...

  4. ArcGIS中QueryTask,FindTask,IndentifyTask 之间的区别

    1:QueryTask是一个进行空间和属性查询的功能类,它可以在某个地图服务的某个子图层内进行查询,顺便需要提一下的是,QueryTask进行查询的地图服务并 不必项加载到Map中进行显示.Query ...

  5. hexo next主题深度优化(四),自定义一个share功能,share.js。

    文章目录 背景: 开始: 引入资源: 代码 关键的一步 附:方便学习的小demo 一次成功后还出现上面的bug 结束 2018.12.23发现bug(读者可忽略) 个人博客:https://mmmmm ...

  6. scrapy的使用-scrapy shell

    进入     该目录下执行scrapy shell 文件, 在命令行可执行该文件中链接的xpath语法,和BeautifulSoup语法.

  7. 9款很棒的网页绘制图表JavaScript框架脚本

    推荐9款很棒的可在网页中绘制图表的JavaScript脚本,这些有趣的JS脚本可以帮助你快速方便的绘制图表(线.面.饼.条…),其中包括jQuery.MooTools.Prototype和一些其它的J ...

  8. 网络请求NSLog结果不全

    碰到了两次 NSLog请求结果只有一部分 如果NSLog语句中没有汉语就可以全部输出了,不清楚原因. NSLog(@"%@",object);//这样结果是全的 NSLog(@&q ...

  9. arm-linux-readelf 的使用

    1. 读 elf 文件开始的文件头部 [arm@localhost gcc]$ arm­linux­readelf ­h hello ELF Header: Magic:   7f 45 4c 46 ...

  10. 关于VSCode的一些常用插件和一些常用设置

    常用插件: .Beautify :格式化 html ,js,css .Bracket Pair Colorizer :给括号加上不同的颜色,便于区分不同的区块,使用者可以定义不同括号类型和不同颜色 . ...