《DSP using MATLAB》Problem 7.27

《DSP using MATLAB》Problem 7.27

《DSP using MATLAB》Problem 7.27

代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% 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]);

  运行结果:

《DSP using MATLAB》Problem 7.27

《DSP using MATLAB》Problem 7.27

《DSP using MATLAB》Problem 7.27

上一篇:《Java基础知识》Java 反射详解


下一篇:●BOZJ 3144 [Hnoi2013]切糕