《DSP using MATLAB》Problem 7.14
代码:
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 7.14 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % bandpass
ws1 = 0.25*pi; wp1 = 0.35*pi; wp2=0.65*pi; ws2=0.75*pi;
delta1 = 0.05; delta2 = 0.01;
tr_width = min(wp1-ws1, ws2-wp2);
f = [ws1, wp1, wp2, ws2]/pi; [Rp, As] = delta2db(delta1, delta2) M = ceil((As-7.95)/(2.285*tr_width)) + 1; % Kaiser Window
if As > 21 || As < 50
beta = 0.5842*(As-21)^0.4 + 0.07886*(As-21);
else
beta = 0.1102*(As-8.7);
end fprintf('\nKaiser Window method, Filter Length: M = %d. beta = %.4f\n', M, beta); n = [0:1:M-1]; wc1 = (ws1+wp1)/2; wc2 = (ws2+wp2)/2; %wc = (ws + wp)/2, % ideal LPF cutoff frequency hd = ideal_lp(wc2, M) - ideal_lp(wc1, M);
w_kai = (kaiser(M, beta))'; h = hd .* w_kai;
[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: wp2/delta_w+1))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); As = -round(max(db(1 : 1 : floor(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.14 ideal_lp Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.3 0.4]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n, w_kai); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Kaiser Window'); subplot(2,2,3); stem(n, h); axis([0 M-1 -0.3 0.4]); 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,-42,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'42';' 0']);
set(gca,'XTickMode','manual','XTick',[0,f,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); figure('NumberTitle', 'off', 'Name', 'Problem 7.14 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,-42,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'42';' 0']);
set(gca,'XTickMode','manual','XTick',[0,f,1+f,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,f,1+f,2]);
set(gca,'YTickMode','manual','YTick',[0,0.5, 1]) 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.14 Amp Res of 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,f,2]); %% +++++++++++++++++++++++++++++++++++++++++
%% fir1 function method
%% +++++++++++++++++++++++++++++++++++++++++
f = [ws1, wp1, wp2, ws2]/pi;
m = [0 1 0];
ripple = [0.01 0.05 0.01];
[N, wc, beta, ftype] = kaiserord(f,m,ripple);
fprintf('\n------------ kaiserord function: START---------------\n');
fprintf('\n--------- results used by fir1 function ---------\n');
N
wc
beta
ftype
fprintf('------------- kaiserord function: FINISH---------------\n');
%h_check = fir1(M-1, [wc1 wc2]/pi, 'stop', window(@kaiser, M));
%h_check = fir1(N, wc, ftype, window(@kaiser, N+1));
h_check = fir1(N, wc, ftype, kaiser(N+1, beta)); [db, mag, pha, grd, w] = freqz_m(h_check, [1]);
[Hr,ww,P,L] = ampl_res(h_check); As = -round(max(db(1 : 1 : floor(ws1/delta_w)+1 ))); % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As); Rp = -(min(db(wp1/delta_w :1: wp2/delta_w+1))); % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp); [delta1, delta2] = db2delta(Rp, As) %% -------------------------------------------
%% plot
%% -------------------------------------------
figure('NumberTitle', 'off', 'Name', 'Problem 7.14 fir1 Method')
set(gcf,'Color','white'); subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.3 0.4]); grid on;
xlabel('n'); ylabel('hd(n)'); title('Ideal Impulse Response'); subplot(2,2,2); stem(n, w_kai); axis([0 M-1 0 1.1]); grid on;
xlabel('n'); ylabel('w(n)'); title('Kaiser Window'); subplot(2,2,3); stem([0:N], h_check); axis([0 M -0.3 0.4]); 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,-42,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'42';' 0']);
set(gca,'XTickMode','manual','XTick',[0,f,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB'); figure('NumberTitle', 'off', 'Name', 'Problem 7.14 h_check(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,-42,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'42';' 0']);
set(gca,'XTickMode','manual','XTick',[0,f,1+f,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,f,1+f,2]);
set(gca,'YTickMode','manual','YTick',[0,0.5, 1]) 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');
运行结果:
使用fir1函数得到的对应结果
《DSP using MATLAB》Problem 7.14的更多相关文章
- 《DSP using MATLAB》Problem 6.14
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 5.14
说明:这两个小题的数学证明过程都不会,欢迎博友赐教. 直接上代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 4.14
代码: %% ---------------------------------------------------------------------------- %% Output Info a ...
- 《DSP using MATLAB》Problem 2.14
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 8.14
代码: %% ------------------------------------------------------------------------ %% Output Info about ...
- 《DSP using MATLAB》Problem 7.26
注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...
- 《DSP using MATLAB》Problem 6.8
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 5.7
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
- 《DSP using MATLAB》Problem 7.27
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...
随机推荐
- PHP用post来进行Soap请求
最近调了一个Soap请求C# webservice的项目.网上坑不少. 使用原生的SoapClient库请求也是失败.只好用post来进行模拟了.代码贴出来,给大家参考一下. <?php nam ...
- F2833x 调用DSP函数库实现复数的FFT的方法
转载自:http://blog.csdn.net/aeecren/article/details/67644363:个人觉得写的很详细,值得一看 在数字信号处理中,FFT变换是经常使用到的,在DSP中 ...
- 最近工作再弄基于bootstrap的定制sass
封装各种组件如 button table 当然..我只才做完两个. 比如table 抽出很多类以后可以配置的值 还有button 目录结构大致是 scss主要css文件 base和components ...
- vue项目使用前端框架开发,实现滑动效果,若不刷新页面则无法达到预期效果的问题及解决方法
滑动等效果的初始化时机很重要,在vue项目开发中,需到mounted()钩子函数 (当组件中的DOM结构被渲染好并放到页面中后,会执行这个钩子函数,此时即可初始化滑动效果的js代码). 若组件未挂载到 ...
- phpstrom常用快捷键
mark一下 格式化(应设置QQ快捷键) 自动代码提示 Ctrl+Alt+L Ctrl+J 页面查找 页面查找并替换 Ctrl+F Ctrl+R 全局查找 全局查找并替换 ...
- cocos图片的选择以及压缩
我们在使用cocos在windows平台下,运行速度很快很流畅,很强大,可是当我们打包成apk文件,在手机上运行的时候,流畅度很可能降低,甚至还有间歇性内存彪高. 游戏内存优化我们一般可以从这么3个方 ...
- Beta冲刺 4
前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/10123035.html 作业博客:https://edu.cnblogs.com/campus ...
- Linux:Gentoo系统的安装笔记(三)
这期笔记将是gentoo安装的最后一期了,虽然已经配置内核了,但是也要完成剩下的安装步骤,这离安装完成已经不远了,继续加油!!! 如果中断了安装,请看第二期的笔记进行恢复安装,但请重新编译一次内核,否 ...
- Spring Boot 整合JDBCTemplate
1. 首先配置pom.xml 1.1 dbcm2 是数据源类型,表示配置dataSource的方式 1.2 spring-boot-starter-jdbc是表示让spring boot 支持jdbc ...
- TCP学习总结(一)
在学习的过程中,相信大家都有过“学了就忘“这种经历,又特别是TCP/IP知识点密集的通信协议,所以在此总结一下自己学到的皮毛,希望对自己对大家也有所帮助. 这篇博客主要讲运输层TCP和UDP的东西,I ...