zoukankan      html  css  js  c++  java
  • 《DSP using MATLAB》Problem 7.23

    %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    %%            Output Info about this m-file
    fprintf('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 7.23 
    
    ');
    
    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('
    Actual Passband Ripple is %.4f dB.
    ', Rp);
    As = -round(max(db(floor(0.35*pi/delta_w)+1 : 1 : 501)));        % Min Stopband attenuation
    fprintf('
    Min Stopband attenuation is %.4f dB.
    ', 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]);
    

      运行结果:

    牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
  • 相关阅读:
    生成器 和 生成器 表达式
    函数的三大器
    02.python网络爬虫第二弹(http和https协议)
    python网络爬虫第三弹(<爬取get请求的页面数据>)
    线程
    网络编程
    分时操作系统 与 多道程序系统
    javascript原型深入解析2--Object和Function,先有鸡先有蛋
    javascript原型深入解析1-prototype 和原型链、js面向对象
    js模块化
  • 原文地址:https://www.cnblogs.com/ky027wh-sx/p/10590221.html
Copyright © 2011-2022 走看看