《DSP using MATLAB》Problem 7.26
注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数。这里取M=31,过渡带里采样值抄书上的。
代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info about this m-file fprintf('\n***********************************************************\n'); fprintf(' <DSP using MATLAB> Problem 7.26 \n\n');banner(); %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% highpass, Only Type-1 filter ws1 = 0.4*pi; wp1 = 0.6*pi; As = 50; Rp = 0.004; tr_width = (wp1-ws1);T2 = 0.5925; T1=0.1099; M = 31; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l; n = [0:1:M-1]; wc1 = (ws1+wp1)/2; Hrs = [zeros(1,7),T1,T2,ones(1,14),T2,T1,zeros(1,6)]; % Ideal Amp Res sampled Hdr = [0, 0, 1, 1]; wdl = [0, 0.4, 0.6, 1]; % Ideal Amp Res for plotting k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;%% -------------------------------------------------- %% Type-1 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_Type1(h);Rp = -(min(db(floor(wp1/delta_w)+1 :1: 501))); % Actual Passband Ripple fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp);As = -round(max(db(1:1:floor(0.4*pi/delta_w)+1))); % Min Stopband attenuation fprintf('\nMin Stopband attenuation is %.4f dB.\n', As);[delta1, delta2] = db2delta(Rp, As)% Plotfigure('NumberTitle', 'off', 'Name', 'Problem 7.26a FreSamp Method') set(gcf,'Color','white'); subplot(2,2,1); plot(wl(1:16)/pi, Hrs(1:16), '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.4,0.6,1]); xlabel('frequency in \pi nuits'); ylabel('Hr(k)'); title('Frequency Samples: M=31,T1=0.5925,T2=0.1099'); grid on;subplot(2,2,2); stem(l, h); axis([-1, M, -0.4, 0.6]); grid on; xlabel('n'); ylabel('h(n)'); title('Impulse Response');subplot(2,2,3); plot(ww/pi, Hr, 'r', wl(1:16)/pi, Hrs(1:16), '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.4,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,-60,-51,0]); set(gca,'YTickLabelMode','manual','YTickLabel',['90';'60';'51';' 0']); set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]);figure('NumberTitle', 'off', 'Name', 'Problem 7.26 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,-60,-51,0]) set(gca,'YTickLabelMode','manual','YTickLabel',['90';'60';'51';' 0']); set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,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.4,0.6,1,1.4,1.6,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.26 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.4,0.6,1]);%% ------------------------------------ %% fir2 Method %% ------------------------------------ f = [0 ws1 wp1 pi]/pi; m = [0 0 1 1 ]; h_check = fir2(M+1, f, m); % if M is odd, then M+1; order [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: 501))); % Actual Passband Ripple fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(1:1:floor(0.4*pi/delta_w)+1 ))); % Min Stopband attenuation fprintf('\nMin Stopband attenuation is %.4f dB.\n', As);[delta1, delta2] = db2delta(Rp, As)figure('NumberTitle', 'off', 'Name', 'Problem 7.26 fir2 Method') set(gcf,'Color','white'); subplot(2,2,1); stem(n, h); axis([0 M-1 -0.4 0.6]); 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+1], h_check); axis([0 M+1 -0.4 0.6]); 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,-67,-21,0]) set(gca,'YTickLabelMode','manual','YTickLabel',['90';'67';'21';' 0']); set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1]); xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');figure('NumberTitle', 'off', 'Name', 'Problem 7.26 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,-67,-21,0]); set(gca,'YTickLabelMode','manual','YTickLabel',['90';'67';'21';' 0']); set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,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.4,0.6,1,1.4,1.6,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.26 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.4,0.6,1]);
运行结果:
振幅响应
转载于:https://www.cnblogs.com/ky027wh-sx/p/10699672.html
《DSP using MATLAB》Problem 7.26相关推荐
- 《DSP using MATLAB》Problem 7.16
使用一种固定窗函数法设计带通滤波器. 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《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 6.6
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.36
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 8.22
时光飞逝,亲朋会一个一个离我们远去,孤独漂泊一阵子后,我们自己也要离开, 代码: %% -------------------------------------------------------- ...
- 《DSP using MATLAB》Problem 8.1
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
最新文章
- 用MyEclipse开发Spring入门
- 区块链有哪些技术特征
- BIOS与CMOS区别
- 最新行政区划编码数据
- phpredis中文手册——《redis中文手册》 php版
- GDCM:2个DICOM文件的diff测试程序
- mysql修改字段非必输_mysql有些字段是非必填的,传空要查所有数据该怎么处理?...
- 【统计学习方法】感知机笔记
- 网站等保测评针对服务器,互联互通测评知识分享之信息安全建设要点
- mysql 按日期拆分成多条记录_mysql性能优化2 设计规范 设计原则 结构优化 拆分 配置优化...
- Bokeh 添加注释
- 台式计算机读取不了移动硬盘,电脑识别不了硬盘的原因
- JavaWeb POI 导出Excel
- 【电路与电子技术】笔记 (完结)
- LaTeX制作表格---学习笔记
- mac 更新 nodenpm
- 改进后的速算小游戏(2011211909 苟玲、2011211933 郝怡然)
- 掌握 Windows 命令行界面:常用 DOS 命令简介
- 把手账打印成书 把回忆装订成册
- 费城交响乐团将于5月16日至28日开启2019年中国巡演之旅
热门文章
- java mysql分层_java-数据库连接,分层实现增删改查测试
- sqlserver 数据库排它锁_MySQL-锁
- dart参数传方法_Flutter必备Dart语言快速入门
- iphone换机数据迁移_怎么一键换机?换新机迁移数据必看教程!
- XSS-Payloads集合
- 华为服务器如何开机自动启动不了,华为手机开不了机停在开机画面怎么办【详解】...
- Excel 求差集和并集
- 微软Skype即将抛弃Windows Phone 8和8.1用户
- Map接口与学习系列(二)---LinkedHashMap
- LINUX 下通过lsof恢复被误删除的文件