代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% 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的更多相关文章

  1. 《DSP using MATLAB》Problem 6.14

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

  2. 《DSP using MATLAB》Problem 5.14

    说明:这两个小题的数学证明过程都不会,欢迎博友赐教. 直接上代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...

  3. 《DSP using MATLAB》Problem 4.14

    代码: %% ---------------------------------------------------------------------------- %% Output Info a ...

  4. 《DSP using MATLAB》Problem 2.14

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  5. 《DSP using MATLAB》Problem 8.14

    代码: %% ------------------------------------------------------------------------ %% Output Info about ...

  6. 《DSP using MATLAB》Problem 7.26

    注意:高通的线性相位FIR滤波器,不能是第2类,所以其长度必须为奇数.这里取M=31,过渡带里采样值抄书上的. 代码: %% +++++++++++++++++++++++++++++++++++++ ...

  7. 《DSP using MATLAB》Problem 6.8

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

  8. 《DSP using MATLAB》Problem 5.7

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

  9. 《DSP using MATLAB》Problem 7.27

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

随机推荐

  1. Linux内核分析--进程创建,执行,切换

    学号:351 原创作品转载请注明出处本实验来源 https://github.com/mengning/linuxkernel/ 实验要求 从整理上理解进程创建.可执行文件的加载和进程执行进程切换,重 ...

  2. Unity 关于AssetBundle读取场景

    一. 1.关于如何打包成ab包,就不多说了,网上很多教程,siki学院也有siki老师的免费视频教程挺详细的,可以看看 http://www.sikiedu.com/my/course/74 2.为了 ...

  3. union、union all 、distinct的区别和用途

    1.从用途上讲 它们都具有去重的效果 2.从效率上讲 distinct通常不建议使用,效率较低;union all 和union 而言,union all效率更高;原因是:union 相当于多表查询出 ...

  4. JAVA Number与Math类

    Number类: 当要用到数字的时候,我们除了使用内置数据类型byte,int,double等来声明,我们还把它声明为一个对象: 所有的包装类(Integer.Long.Byte.Double.Flo ...

  5. hadoop2.6.0高可靠及yarn 高可靠搭建

    以前用hadoop2.2.0只搭建了hadoop的高可用,但在hadoop2.2.0中始终没有完成YARN HA的搭建,直接下载了hadoop最新稳定版本2.6.0完成了YARN HA及HADOOP ...

  6. 服务集群session问题

    1. http协议本身无状态,可通过Session与Cookie记录前端与后端服务器的交互状态: 2. 但是每次客户端回传必须在头信息中带有cookie, 如果session过多,会增加数据传输量: ...

  7. pytest自动化4:fixture之yield实现teardown

    出处:https://www.cnblogs.com/yoyoketang/p/9401554.html 前言: 上一篇介绍了fixture通过scope参数控制setup级别,我们一起来温故下fix ...

  8. shell中脚本与函数的使用策略

    脚本:运行的副作用不影响父环境,开辟了fork子进程; 函数:副作用,定义的变量,数据默认直接添加到了调用者的环境,也是它自己的环境;不想副作用影响调用者环境,就必须主动用local修饰; shell ...

  9. jquery评分插件jquery.raty.js

    1.参考链接 官方地址. 教程一 教程二 2.案例1 引入文件: <!-- 评分插件 --> <script type="text/javascript" src ...

  10. https加密流程

     引用其它博主博客,在这里谢谢这位博主,原博客地址:https://blog.csdn.net/xincai/article/details/51954468 1,下面,用一幅图展示一下https建立 ...