《DSP using MATLAB》Problem 7.23

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

banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
T1 = 0.5
wc = 0.3*pi;
M = 40; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
Hrs = [ones(1, 6), T1, zeros(1, 27), T1, ones(1, 5)];      % Ideal Amp Res sampled
Hdr = [1, 1, 0, 0]; wdl = [0, 0.3, 0.3, 1];                % Ideal Amp Res for plotting
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;

%% ----------------------------------
%%           Type-2 LPF
%% ----------------------------------  
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)]; 
H = Hrs.*exp(j*angH); h = real(ifft(H, M));

[db, mag, pha, grd, w] = freqz_m(h, 1); delta_w = 2*pi/1000;
[Hr, ww, a, L] = Hr_Type2(h);

Rp = -(min(db(1 :1: floor(wc/delta_w)-20)));                      % Actual Passband Ripple
fprintf('\nActual Passband Ripple is %.4f dB.\n', Rp);
As = -round(max(db(floor(0.35*pi/delta_w)+1 : 1 : 501)));        % Min Stopband attenuation
fprintf('\nMin Stopband attenuation is %.4f dB.\n', As);

[delta1, delta2] = db2delta(Rp, As)

%% Plot a

figure('NumberTitle', 'off', 'Name', 'Problem 7.23a')
set(gcf,'Color','white'); 

subplot(2,2,1); plot(wl(1:21)/pi, Hrs(1:21), 'o', wdl, Hdr, 'r'); axis([0, 1, -0.1, 1.1]);
set(gca,'YTickMode','manual','YTick',[0,0.5,1]);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.5,1]);
xlabel('frequency in \pi nuits'); ylabel('Hr(k)'); title('Frequency Samples: M=40, T1=0.5');
grid on;

subplot(2,2,2); stem(l, h); axis([-1, M, -0.1, 0.3]); grid on;
xlabel('n'); ylabel('h(n)'); title('Impulse Response');

subplot(2,2,3); plot(ww/pi, Hr, 'r', wl(1:21)/pi, Hrs(1:21), 'o'); axis([0, 1, -0.2, 1.2]); grid on;
xlabel('frequency in \pi units'); ylabel('Hr(w)'); title('Amplitude Response');
set(gca,'YTickMode','manual','YTick',[0,0.5,1]);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.5,1]);

subplot(2,2,4); plot(w/pi, db); axis([0, 1, -100, 10]); grid on;
xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response');
set(gca,'YTickMode','manual','YTick',[-90,-30,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'30';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.5,1]);

figure('NumberTitle', 'off', 'Name', 'Problem 7.23 h(n)a')
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,-30,0]);
set(gca,'YTickLabelMode','manual','YTickLabel',['90';'30';' 0']);
set(gca,'XTickMode','manual','XTick',[0,0.3,0.5,1,1.7,2]);
subplot(2,2,3); plot(w/pi, mag); grid on; axis([0 2 0 1.2]); 
xlabel('frequency in \pi units'); ylabel('Absolute'); title('Magnitude Response in absolute');
set(gca,'XTickMode','manual','XTick',[0,0.3,0.5,1,1.7,2]);
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.23a Amp Res of h(n) T1=0.5')
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.3,0.5,1,1.7,2]);

  运行结果:

转载于:https://www.cnblogs.com/ky027wh-sx/p/10590221.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值