《DSP using MATLAB》Problem 7.12

阻带衰减50dB,我们选Hamming窗
代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.12 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % highpass
ws1 = 0.4*pi; wp1 = 0.6*pi; As = 50; Rp = 0.004;
tr_width = (wp1-ws1);
M = ceil(6.6*pi/tr_width) + 1; % Hamming Window
fprintf('\nFilter Length: M = %d.\n', M); n = [0:1:M-1]; wc1 = (ws1+wp1)/2; %wc = (ws + wp)/2, % ideal LPF cutoff frequency hd = ideal_lp(pi, M) - ideal_lp(wc1, M);
w_hamm = (hamming(M))'; h = hd .* w_hamm;
[db, mag, pha, grd, w] = freqz_m(h, [1]); delta_w = 2*pi/1000;
[Hr,ww,P,L] = ampl_res(h); Rp = -(min(db(wp1/delta_w+1 :1: 0.9*pi/delta_w))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(1 :1: ws1/delta_w+1 ))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); [delta1, delta2] = db2delta(Rp, As) % Plot figure('NumberTitle', 'off', 'Name', 'Problem 7.12 ideal_lp Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.4 0.3]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n, w_hamm); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Hamming Window'); subplot(2,2,3); stem(n, h); axis([0 M-1 -0.4 0.3]); grid on;
xlabel('n'); ylabel('h(n)'); title('Actual Impulse Response'); subplot(2,2,4); plot(w/pi, db); axis([0 1 -100 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-90,-52,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'52';' 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.12 h(n) ideal_lp Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -100 10]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-90,-52,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'52';' 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 2 -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.0,0.5,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.12 h(n)')
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 - delta1,1, 1 + delta1])
%set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
%set(gca,'XTickMode','manual','XTick',[0,0.4,0.6,1,1.4,1.6,2]); h_check = fir1(M, wc1/pi, 'high');
[db, mag, pha, grd, w] = freqz_m(h_check, [1]);
[Hr,ww,P,L] = ampl_res(h_check); figure('NumberTitle', 'off', 'Name', 'Problem 7.12 fir1 Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.4 0.3]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n, w_hamm); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Hanning Window'); subplot(2,2,3); stem([0:M], h_check); axis([0 M -0.4 0.5]); grid on;
xlabel('n'); ylabel('h\_check(n)'); title('Actual Impulse Response'); subplot(2,2,4); plot(w/pi, db); axis([0 1 -100 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-90,-52,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'52';' 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.12 h(n) fir1 Method')
set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -100 10]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-90,-52,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'52';' 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.0,0.5,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');
运行结果:
Hamming窗长度为M=34,实际最小阻带衰减为52dB,满足设计要求。



振幅响应的高通部分

低阻部分

下面是用fir1函数(默认Hamming窗)来求得脉冲响应,再计算其幅度响应(dB和Absolute单位)、相位响应和群延迟响应,


可以看出,两种方法得到的幅度响应和相位响应在接近π的较高频率部分,还是有差别的。
《DSP using MATLAB》Problem 7.12的更多相关文章
- 《DSP using MATLAB》Problem 6.12
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 5.12
1.从别的地方找的证明过程: 2.代码 function x2 = circfold(x1, N) %% Circular folding using DFT %% ----------------- ...
- 《DSP using MATLAB》Problem 8.12
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 4.12
代码: function [As, Ac, r, v0] = invCCPP(b0, b1, a1, a2) % Determine the signal parameters Ac, As, r, ...
- 《DSP using MATLAB》Problem 3.12
- 《DSP using MATLAB》Problem 7.6
代码: 子函数ampl_res function [Hr,w,P,L] = ampl_res(h); % % function [Hr,w,P,L] = Ampl_res(h) % Computes ...
- 《DSP using MATLAB》Problem 6.22
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 6.8
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 5.21
证明: 代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
随机推荐
- pm2 日常使用
1. pm2 是什么? 日常开发中需要启动一个node项目,需要用npm run …,,如果终端被关掉,程序也就自动停止,有时候几个项目一起跑起来,好几个终端开着,个人不太喜欢,有一神器可以解决:pm ...
- eclipse安装插件配置Android开发环境
安卓版本与sdk的对应 转载自: https://blog.csdn.net/cx776474961/article/details/79501740 最近学习Android开发,电脑已有开发we ...
- 浅谈JS数据遍历的几种方式
遍历对象(数组)是我们日常撸码的必不可少的部分,如何从性能上优化代码,提高运行效率?下文为你揭开真像: 第一种:普通的for循环 for(j = 0; j < arr.length; j++) ...
- _quest_random
-- 随机任务-- 可以实现玩家随机获取任务-- 小技巧:需要控制物品法防,在_function_menu表配置物品indexID为28 `comment`备注 `questId`任务ID `chan ...
- 表单提交:button input submit 的区别
http://harttle.com/2015/08/03/form-submit.html 最近项目代码中的表单提交的方式已经百花齐放了,现在用这篇文章来整理一下不同表单提交方式的区别,给出最佳实践 ...
- js 字符串,new String() 与 String()
function showCase(value) { switch(value) { case 'A': console.log('Case A'); break; case 'B': console ...
- please select android sdk(出现小红叉)
问题原因: 在项目中通过 git 协同开发,项目是 kotlin 与 Java 混合开发.在 build.gradle 中添加依赖之后就出现这个问题了,点击运行无法编译. 在网上找了各种解决办法都没能 ...
- Android 虹软2.0人脸识别,注册失败问题 分析synchronized的作用
人脸识别需要init初始化(FaceServer中),离开时需要unInit销毁:当一个含有人脸识别的界面A跳向另一个含有人脸识别的界面B时,由于初始化和销毁都是对FaceServer类加锁(sync ...
- nginx ----> 官网about页面(翻译)
Nginx about链接:https://nginx.org/en/ nginx 基本的HTTP服务器功能其他HTTP服务器功能邮件代理服务器功能TCP / UDP代理服务器功能架构和可扩展性经测试 ...
- OpenStack笔记
*********virsh xml文件解读****************************** https://libvirt.org/format.html https://libvirt ...