ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

《DSP using MATLAB》Problem 7.27

2019-04-14 21:43:16  阅读:389  来源: 互联网

标签:gca set title 7.27 manual ylabel using Problem pi


代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%%            Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf('        <DSP using MATLAB> Problem 7.27 \n\n');

banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

% bandpass
ws1 = 0.25*pi; wp1 = 0.35*pi; wp2=0.65*pi; ws2 = 0.75*pi;
M=40;
delta_w = 2*pi/1000;

%% ------------------------------------
%%     fir2 Method
%% ------------------------------------
f = [0 ws1 wp1 wp2 ws2 pi]/pi;
m = [0  1  2   2    1  0 ];
h_check = fir2(M-1, f, m, hamming(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, b, L] = Hr_Type2(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)+1)));             % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp);
As = -round(max(db(1:1:floor(0.75*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.27 fir2 Method')
set(gcf,'Color','white'); 

subplot(2,1,1); stem([0:M-1], h_check); axis([0 M-1 -0.7 0.9]); grid on;
xlabel('n'); ylabel('h\_check(n)'); title('Actual Impulse Response');

subplot(2,1,2); plot(w/pi, db); axis([0 1 -70 10]); grid on;
set(gca,'YTickMode','manual','YTick',[-60,-21,0])
set(gca,'YTickLabelMode','manual','YTickLabel',['60';'21';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.25,0.35,0.65,0.75,1]);
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');


figure('NumberTitle', 'off', 'Name', 'Problem 7.27 h(n) fir2 Method')
set(gcf,'Color','white'); 

subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -70 10]); 
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
set(gca,'YTickMode','manual','YTick',[-60,-21,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['60';'21';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.25,0.35,0.65,0.75,1,1.25,1.35,1.65,1.75,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.25,0.35,0.65,0.75,1,1.25,1.35,1.65,1.75,2]);
set(gca,'YTickMode','manual','YTick',[0,1.0,2.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.27 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, 1, 1.98,2.02]);
%set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.25,0.35,0.65,0.75,1]);

  运行结果:

 

标签:gca,set,title,7.27,manual,ylabel,using,Problem,pi
来源: https://www.cnblogs.com/ky027wh-sx/p/10707166.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有