代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.25 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % bandpass
ws1 = 0.3*pi; wp1 = 0.4*pi; wp2 = 0.5*pi; ws2 = 0.6*pi; As = 50; Rp = 0.5;
tr_width = min((wp1-ws1), (ws2-wp2)); T2 = 0.5925; T1=0.1099;
M = 60; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
n = [0:1:M-1]; wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2; Hrs = [zeros(1,10),T1,T2,ones(1,4),T2,T1,zeros(1,25),T1,T2,ones(1,4),T2,T1,zeros(1,9)]; % Ideal Amp Res sampled
Hdr = [0, 0, 1, 1, 0, 0]; wdl = [0, 0.3, 0.4, 0.5, 0.6, 1]; % Ideal Amp Res for plotting
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1; %% --------------------------------------------------
%% Type-2 BPF
%% --------------------------------------------------
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H, M)); [db, mag, pha, grd, w] = freqz_m(h, [1]); delta_w = 2*pi/1000;
%[Hr,ww,P,L] = ampl_res(h);
[Hr, ww, a, L] = Hr_Type2(h); Rp = -(min(db(floor(wp1/delta_w)+1 :1: floor(wp2/delta_w)))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(ws2/delta_w+1 : 1 : 501))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); [delta1, delta2] = db2delta(Rp, As) % Plot figure('NumberTitle', 'off', 'Name', 'Problem 7.25a FreSamp Method')
set(gcf,'Color','white');
subplot(2,2,1); plot(wl(1:31)/pi, Hrs(1:31), 'o', wdl, Hdr, 'r'); axis([0, 1, -0.1, 1.1]);
set(gca,'YTickMode','manual','YTick',[0,0.5,1]);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1]);
xlabel('frequency in \pi nuits'); ylabel('Hr(k)'); title('Frequency Samples: M=60,T1=0.5925,T2=0.1099');
grid on; subplot(2,2,2); stem(l, h); axis([-1, M, -0.2, 0.2]); grid on;
xlabel('n'); ylabel('h(n)'); title('Impulse Response'); subplot(2,2,3); plot(ww/pi, Hr, 'r', wl(1:31)/pi, Hrs(1:31), 'o'); axis([0, 1, -0.2, 1.2]); grid on;
xlabel('frequency in \pi units'); ylabel('Hr(w)'); title('Amplitude Response');
set(gca,'YTickMode','manual','YTick',[0,0.5,1]);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1]); subplot(2,2,4); plot(w/pi, db); axis([0, 1, -100, 10]); grid on;
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response');
set(gca,'YTickMode','manual','YTick',[-90,-54,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'54';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1]); figure('NumberTitle', 'off', 'Name', 'Problem 7.25 h(n) FreSamp Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -120 10]);
set(gca,'YTickMode','manual','YTick',[-90,-54,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'54';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1,1.4,1.5,1.6,1.7,2]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1,1.4,1.5,1.6,1.7,2]);
set(gca,'YTickMode','manual','YTick',[0,1.0]); subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay'); figure('NumberTitle', 'off', 'Name', 'Problem 7.25 AmpRes of h(n), FreSamp Method')
set(gcf,'Color','white'); plot(ww/pi, Hr); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Hr'); title('Amplitude Response');
set(gca,'YTickMode','manual','YTick',[-delta2, 0,delta2, 1-0.0258, 1,1+0.0258]);
%set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1]); %% ------------------------------------
%% fir2 Method
%% ------------------------------------
f = [0 ws1 wp1 wp2 ws2 pi]/pi;
m = [0 0 1 1 0 0];
h_check = fir2(M, f, m);
[db, mag, pha, grd, w] = freqz_m(h_check, [1]);
%[Hr,ww,P,L] = ampl_res(h_check);
[Hr, ww, a, L] = Hr_Type1(h_check); fprintf('\n----------------------------------\n');
fprintf('\n fir2 function Method \n');
fprintf('\n----------------------------------\n'); Rp = -(min(db(floor(wp1/delta_w)+1 :1: floor(wp2/delta_w)))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp);
As = -round(max(db(0.65*pi/delta_w+1 : 1 : 501))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); [delta1, delta2] = db2delta(Rp, As) figure('NumberTitle', 'off', 'Name', 'Problem 7.25 fir2 Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, h); axis([0 M-1 -0.2 0.2]); grid on;
xlabel('n'); ylabel('h(n)'); title('Impulse Response'); %subplot(2,2,2); stem(n, w_ham); axis([0 M-1 0 1.1]); grid on;
%xlabel('n'); ylabel('w(n)'); title('Hamming Window'); subplot(2,2,3); stem([0:M], h_check); axis([0 M -0.2 0.3]); grid on;
xlabel('n'); ylabel('h\_check(n)'); title('Actual Impulse Response'); subplot(2,2,4); plot(w/pi, db); axis([0 1 -120 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-90,-66,-22,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'66';'22';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); figure('NumberTitle', 'off', 'Name', 'Problem 7.25 h(n) fir2 Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -120 10]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-90,-66,-22,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'66';'22';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1,1.4,1.5,1.6,1.7,2]); subplot(2,2,3); plot(w/pi, mag); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1,1.4,1.5,1.6,1.7,2]);
set(gca,'YTickMode','manual','YTick',[0,1.0]); subplot(2,2,2); plot(w/pi, pha); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Phase Response in Radians');
subplot(2,2,4); plot(w/pi, grd*pi/180); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Rad'); title('Group Delay'); figure('NumberTitle', 'off', 'Name', 'Problem 7.25 AmpRes of h(n),fir2 Method')
set(gcf,'Color','white'); plot(ww/pi, Hr); grid on; %axis([0 1 -100 10]);
xlabel('frequency in \pi units'); ylabel('Hr'); title('Amplitude Response');
set(gca,'YTickMode','manual','YTick',[-0.08, 0,0.08, 1-0.04, 1,1+0.04]);
%set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1]);

  运行结果:

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

  1. 《DSP using MATLAB》Problem 8.25

    用match-z方法,将模拟低通转换为数字低通 代码: %% --------------------------------------------------------------------- ...

  2. 《DSP using MATLAB》示例Example7.25

    今天清明放假的第二天,早晨出去吃饭时天气有些阴,十点多开始“清明时节雨纷纷”了. 母亲远在他乡看孙子,挺劳累的.父亲照顾生病的爷爷…… 我打算今天把<DSP using MATLAB>第7 ...

  3. 《DSP using MATLAB》Problem 7.27

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

  4. 《DSP using MATLAB》Problem 7.14

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

  5. 《DSP using MATLAB》Problem 7.13

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

  6. 《DSP using MATLAB》Problem 6.23

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

  7. 《DSP using MATLAB》Problem 5.24-5.25-5.26

    代码: function y = circonvt(x1,x2,N) %% N-point Circular convolution between x1 and x2: (time domain) ...

  8. 《DSP using MATLAB》Problem 4.21

    快到龙抬头,居然下雪了,天空飘起了雪花,温度下降了近20°. 代码: %% -------------------------------------------------------------- ...

  9. 《DSP using MATLAB》Problem 4.15

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

随机推荐

  1. Django基础-02

    django的介绍: Django 中提供了开发网站经常用到的模块,常见的代码都为你写好了,通过减少重复的代码,Django 使你能够专注于 web 应用上有 趣的关键性的东西.为了达到这个目标,Dj ...

  2. Linux系统的磁盘管理

    Linux系统的磁盘管理有三个命令:df.du.fdisk. df:列出Linux中所有文件系统的整体磁盘使用量: du:对文件和目录所占用磁盘空间的查看: fdisk:用于磁盘分区时列出所有的磁盘. ...

  3. 掩码图制作----c语言贴图

    1.首先你得有一张图,比如这样的: 2.用PS打开他... 3.左边工具栏里(快速选择工具W),选想显示的部分 4.ctrl+c复制一下,新建一张黑底图粘贴上去或者白底图时选中显示区即花瓣右键反向右键 ...

  4. Asp.Net Core MongoDB

    废话不说直接上代码: using MongoDB.Bson.Serialization.Attributes; namespace XL.Core.MongoDB { public interface ...

  5. Async CallBack promise fetch

    Callback (回调函数) 在计算机程序设计中,回调函数,或简称回调(Callback 即call then back 被主函数调用运算后会返回主函数),是指通过函数参数传递到其它代码的,某一块可 ...

  6. lvs用户空间命令ipvsadm

    ipvs工作在内核空间,而ipvsadm工作在用户空间,是负责管理集群服务编写规则的命令行工具 ipvsadm需要手动安装. $ yum -y install ipvsadm ipvsadm管理命令 ...

  7. border-radius,box-shadow兼容性解决办法

    css3 border-radius不支持IE8/IE7的四种解决方法 标签: cssborder-radius兼容性   时间:2016-07-18 css3 border-radius用于设置HT ...

  8. linux 常见技巧

    1.# :表示权限用户(如:root) $:表示普通用户 开机提示:login:输入用户名 password:输入口令 用户是系统注册用户成功登陆后, 可以进入相应的用户环境. 退出当前shell,输 ...

  9. ssm配置文件叙述

    spring+springmvc+mybatis框架中用到了三个XML配置文件:web.xml,spring-mvc.xml,spring-mybatis.xml.第一个不用说,每个web项目都会有的 ...

  10. thinkphp5.0如何隐藏index.php入口文件

    隐藏入口文件 public/index.php 同级的.htaccess文件 [ Apache ] 方法1: <IfModule mod_rewrite.c> Options +Follo ...