《DSP using MATLAB》Problem 7.25
代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% 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)% Plotfigure('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]);
运行结果:
转载于:https://www.cnblogs.com/ky027wh-sx/p/10685613.html
《DSP using MATLAB》Problem 7.25相关推荐
- 《DSP using MATLAB》示例Example7.25
今天清明放假的第二天,早晨出去吃饭时天气有些阴,十点多开始"清明时节雨纷纷"了. 母亲远在他乡看孙子,挺劳累的.父亲照顾生病的爷爷-- 我打算今天把<DSP using MA ...
- 《DSP using MATLAB》Problem 7.36
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 8.22
时光飞逝,亲朋会一个一个离我们远去,孤独漂泊一阵子后,我们自己也要离开, 代码: %% -------------------------------------------------------- ...
- 《DSP using MATLAB》Problem 8.1
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 5.7
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 6.24
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 6.12
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 6.20
先放子函数: function [C, B, A, rM] = dir2fs_r(h, r);% DIRECT-form to Frequency Sampling form conversion % ...
- 《DSP using MATLAB》Problem 7.26
注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 6.6
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
最新文章
- Quartz.NET 架构与源代码分析系列 part 1 :Quartz.NET 入门
- 【译】使用Jwt身份认证保护 Asp.Net Core Web Api
- 在Windows2003 SP2上安装VS2005SP1遇到的问题
- 7-65 藏头诗 (15 分)
- 1.5 为什么正则化可以减少过拟合?
- Zookeeper11问
- 智能视频监控中的多目标跟踪分析
- 如何用计算机管理员权限,如何以管理员身份运行电脑?急
- kitti数据集calib.txt文件
- 禁止收录与跟踪-- Robots 文件优化和Nofollow 优化
- jnhs中国的省市县区邮编坐标mysql数据表
- 智能颈部按摩仪设计——2.开发环境搭建
- sticky-粘性布局
- 谈谈区块链正经的商用场景!
- 如何定义和使用一个 Lambda 表达式
- Linux中uuid是什么?UUID由几部分组成?
- 大数据计算框架与平台--深入浅出分析
- 免费的pdf转word工具
- 【新知实验室】快速实现视频应用
- WSDL——Web Service Description Language
热门文章
- 7-10 统计字符出现次数 (20 point(s))
- 使用Lingo做灵敏度分析
- spring教程笔记5
- android从本地图片导入应用,android – 将图像添加到图库
- C++const类型
- caffe中 solver.prototxt文件
- Keras指定GPU训练模式,设置GPU的使用量
- python 赋值、浅拷贝、深拷贝学习实践
- 面试:Synchronized知识点
- datagrid设置单元格边框_更改 DataGridView 控件中的边框和网格线样式 - Windows Forms .NET Framework | Microsoft Docs...