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

        代码:

    %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    %%            Output Info about this m-file
    fprintf('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 7.10 
    
    ');
    
    banner();
    %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
    
    wp1 = 0.3*pi; ws1 = 0.4*pi; ws2 = 0.6*pi; wp2 = 0.7*pi; 
    As = 50; Rp = 0.2;
    tr_width = min( ws1-wp1, wp2-ws2 );
    M = ceil(6.6*pi/tr_width) + 1;                 % Hamming Window
    fprintf('
    Filter Length is %d.
    ', M);
    
    n = [0:1:M-1];  wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2;
    
    %wc = (ws + wp)/2,                    % ideal LPF cutoff frequency
    
    hd = ideal_lp(wc1, M) + ideal_lp(pi, M) - ideal_lp(wc2, M); 
    w_ham = (hamming(M))';  h = hd .* w_ham;
    [db, mag, pha, grd, w] = freqz_m(h, [1]);  delta_w = 2*pi/1000;
    [Hr,ww,P,L] = ampl_res(h);
    
    Rp = -(min(db(1 : 1 : wp1/delta_w+1)));             % Actual Passband Ripple
    fprintf('
    Actual Passband Ripple is %.4f dB.
    ', Rp);
    
    As = -round(max(db(ws1/delta_w+1 : 1 : ws2/delta_w)));        % Min Stopband attenuation
    fprintf('
    Min Stopband attenuation is %.4f dB.
    ', As);
    
    [delta1, delta2] = db2delta(Rp, As)
    
    %Plot
    
    figure('NumberTitle', 'off', 'Name', 'Problem 7.10 ideal_lp Method')
    set(gcf,'Color','white'); 
    
    subplot(2,2,1); stem(n, hd); axis([0 M-1 -0.2 0.8]); grid on;
    xlabel('n'); ylabel('hd(n)'); title('Ideal 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(n, h); axis([0 M-1 -0.2 0.8]); grid on;
    xlabel('n'); ylabel('h(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,-50,0]);
    set(gca,'YTickLabelMode','manual','YTickLabel',['90';'50';' 0']);
    set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.6,0.7,1]);
    xlabel('frequency in pi units'); ylabel('Decibels'); title('Magnitude Response in dB');
    
    
    figure('NumberTitle', 'off', 'Name', 'Problem 7.10 h(n) ideal_lp Method')
    set(gcf,'Color','white'); 
    
    subplot(2,2,1); plot(w/pi, db); grid on; axis([0 1 -120 10]); 
    set(gca,'YTickMode','manual','YTick',[-90,-50,0])
    set(gca,'YTickLabelMode','manual','YTickLabel',['90';'50';' 0']);
    set(gca,'XTickMode','manual','XTick',[0,0.3,0.4,0.6,0.7,1]);
    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.6,0.7,1,1.3,1.4,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.10 h(n)')
    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.0032, 0,0.0032, 0.9975, 1,1.0025]);
    %set(gca,'YTickLabelMode','manual','YTickLabel',['90';'45';' 0']);
    %set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.55,0.75,1,1.2,1.35,1.55,1.75,2]);
    

      运行结果:

           阻带最小衰减为50dB,满足设计要求。

              用Hamming窗设计的滤波器脉冲响应,其幅度响应(dB和Absolute单位)、相位响应和群延迟响应。

            振幅响应(Absolute单位)

            通带部分

            阻带部分

    牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
  • 相关阅读:
    学习笔记008之Task
    问题: ActivityManager: Warning: Activity not started, its current task has been brought to the front
    问题; No label views point to this text field with an android:labelFor="@+id/@+id/editTextNumber1" attribute
    学习笔记001之[Android开发视频教学].01_06_Android当中的常见控件
    学习笔记002之学习资料
    学习笔记001之环境配置
    设计模式之代理模式
    C# Enum转换
    Json数据序列化对象,及对象序列化为Json格式
    groupby以后取每组前n行
  • 原文地址:https://www.cnblogs.com/ky027wh-sx/p/10458365.html
Copyright © 2011-2022 走看看