博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
《DSP using MATLAB》Problem 7.25
阅读量:4327 次
发布时间:2019-06-06

本文共 7165 字,大约阅读时间需要 23 分钟。

代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%%            Output Info about this m-filefprintf('\n***********************************************************\n');fprintf('        
Problem 7.25 \n\n');banner();%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++% bandpassws1 = 0.3*pi; wp1 = 0.4*pi; wp2 = 0.5*pi; ws2 = 0.6*pi; As = 50; Rp = 0.5;tr_width = min((wp1-ws1), (ws2-wp2));T2 = 0.5925; T1=0.1099;M = 60; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;n = [0:1:M-1]; wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2;Hrs = [zeros(1,10),T1,T2,ones(1,4),T2,T1,zeros(1,25),T1,T2,ones(1,4),T2,T1,zeros(1,9)]; % Ideal Amp Res sampledHdr = [0, 0, 1, 1, 0, 0]; wdl = [0, 0.3, 0.4, 0.5, 0.6, 1]; % Ideal Amp Res for plottingk1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;%% --------------------------------------------------%% Type-2 BPF%% -------------------------------------------------- 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,P,L] = ampl_res(h);[Hr, ww, a, L] = Hr_Type2(h);Rp = -(min(db(floor(wp1/delta_w)+1 :1: floor(wp2/delta_w)))); % Actual Passband Ripplefprintf('\nActual Passband Ripple is %.4f dB.\n', Rp);As = -round(max(db(ws2/delta_w+1 : 1 : 501))); % Min Stopband attenuationfprintf('\nMin Stopband attenuation is %.4f dB.\n', As);[delta1, delta2] = db2delta(Rp, As)% Plotfigure('NumberTitle', 'off', 'Name', 'Problem 7.25a FreSamp Method')set(gcf,'Color','white'); subplot(2,2,1); plot(wl(1:31)/pi, Hrs(1:31), '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.4,0.5,0.6,1]);xlabel('frequency in \pi nuits'); ylabel('Hr(k)'); title('Frequency Samples: M=60,T1=0.5925,T2=0.1099');grid on;subplot(2,2,2); stem(l, h); axis([-1, M, -0.2, 0.2]); grid on;xlabel('n'); ylabel('h(n)'); title('Impulse Response');subplot(2,2,3); plot(ww/pi, Hr, 'r', wl(1:31)/pi, Hrs(1:31), '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.4,0.5,0.6,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,-54,0]);set(gca,'YTickLabelMode','manual','YTickLabel',['90';'54';' 0']);set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1]);figure('NumberTitle', 'off', 'Name', 'Problem 7.25 h(n) FreSamp Method')set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -120 10]); set(gca,'YTickMode','manual','YTick',[-90,-54,0])set(gca,'YTickLabelMode','manual','YTickLabel',['90';'54';' 0']);set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1,1.4,1.5,1.6,1.7,2]);xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');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.3,0.4,0.5,0.6,1,1.4,1.5,1.6,1.7,2]);set(gca,'YTickMode','manual','YTick',[0,1.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.25 AmpRes of h(n), FreSamp 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',[-delta2, 0,delta2, 1-0.0258, 1,1+0.0258]);%set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1]);%% ------------------------------------%% fir2 Method%% ------------------------------------f = [0 ws1 wp1 wp2 ws2 pi]/pi;m = [0 0 1 1 0 0];h_check = fir2(M, f, m);[db, mag, pha, grd, w] = freqz_m(h_check, [1]); %[Hr,ww,P,L] = ampl_res(h_check);[Hr, ww, a, L] = Hr_Type1(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)))); % Actual Passband Ripplefprintf('\nActual Passband Ripple is %.4f dB.\n', Rp);As = -round(max(db(0.65*pi/delta_w+1 : 1 : 501))); % Min Stopband attenuationfprintf('\nMin Stopband attenuation is %.4f dB.\n', As);[delta1, delta2] = db2delta(Rp, As)figure('NumberTitle', 'off', 'Name', 'Problem 7.25 fir2 Method')set(gcf,'Color','white'); subplot(2,2,1); stem(n, h); axis([0 M-1 -0.2 0.2]); grid on;xlabel('n'); ylabel('h(n)'); title('Impulse Response');%subplot(2,2,2); stem(n, w_ham); axis([0 M-1 0 1.1]); grid on;%xlabel('n'); ylabel('w(n)'); title('Hamming Window');subplot(2,2,3); stem([0:M], h_check); axis([0 M -0.2 0.3]); grid on;xlabel('n'); ylabel('h\_check(n)'); title('Actual Impulse Response');subplot(2,2,4); plot(w/pi, db); axis([0 1 -120 10]); grid on;set(gca,'YTickMode','manual','YTick',[-90,-66,-22,0])set(gca,'YTickLabelMode','manual','YTickLabel',['90';'66';'22';' 0']);set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1]);xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');figure('NumberTitle', 'off', 'Name', 'Problem 7.25 h(n) fir2 Method')set(gcf,'Color','white'); subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -120 10]); xlabel('frequency in \pi units'); ylabel('Decibels'); title('Magnitude Response in dB');set(gca,'YTickMode','manual','YTick',[-90,-66,-22,0]);set(gca,'YTickLabelMode','manual','YTickLabel',['90';'66';'22';' 0']);set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1,1.4,1.5,1.6,1.7,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.3,0.4,0.5,0.6,1,1.4,1.5,1.6,1.7,2]);set(gca,'YTickMode','manual','YTick',[0,1.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.25 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.08, 0,0.08, 1-0.04, 1,1+0.04]);%set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.5,0.6,1]);

  运行结果:

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

你可能感兴趣的文章
day7
查看>>
iphone移动端踩坑
查看>>
vs无法加载项目
查看>>
Beanutils基本用法
查看>>
玉伯的一道课后题题解(关于 IEEE 754 双精度浮点型精度损失)
查看>>
《BI那点儿事》数据流转换——百分比抽样、行抽样
查看>>
哈希(1) hash的基本知识回顾
查看>>
Leetcode 6——ZigZag Conversion
查看>>
dockerfile_nginx+PHP+mongo数据库_完美搭建
查看>>
Http协议的学习
查看>>
【转】轻松记住大端小端的含义(附对大端和小端的解释)
查看>>
设计模式那点事读书笔记(3)----建造者模式
查看>>
ActiveMQ学习笔记(1)----初识ActiveMQ
查看>>
Java与算法之(2) - 快速排序
查看>>
Windows之IOCP
查看>>
机器学习降维之主成分分析
查看>>
CTP2交易所成交回报
查看>>
WebSocket & websockets
查看>>
openssl 升级
查看>>
ASP.NET MVC:通过 FileResult 向 浏览器 发送文件
查看>>