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

            代码:

    %% ------------------------------------------------------------------------
    %%            Output Info about this m-file
    fprintf('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 8.21 
    
    ');
    
    banner();
    %% ------------------------------------------------------------------------
    
    Fp = 3.2;                    % analog passband freq in kHz
    Fs = 3.8;                    % analog stopband freq in kHz
    fs = 8;                      % sampling rate in kHz
    
    % -------------------------------
    %       ω = ΩT = 2πF/fs
    % Digital Filter Specifications:
    % -------------------------------
    %wp = 2*pi*Fp/fs;                 % digital passband freq in rad/sec
    wp = Fp;
    %ws = 2*pi*Fs/fs;                 % digital stopband freq in rad/sec
    ws = Fs;
    Rp = 0.5;                        % passband ripple in dB
    As = 45;                         % stopband attenuation in dB
    
    Ripple = 10 ^ (-Rp/20)           % passband ripple in absolute
    Attn = 10 ^ (-As/20)             % stopband attenuation in absolute
    
    % Analog prototype specifications: Inverse Mapping for frequencies
    T = 1;                       % set T = 1
    OmegaP = wp/T;               % prototype passband freq
    OmegaS = ws/T;               % prototype stopband freq
    
    % Analog Chebyshev-1 Prototype Filter Calculation:
    [cs, ds] = afd_chb1(OmegaP, OmegaS, Rp, As);
    
    % Calculation of second-order sections:
    fprintf('
    ***** Cascade-form in s-plane: START *****
    ');
    [CS, BS, AS] = sdir2cas(cs, ds)
    fprintf('
    ***** Cascade-form in s-plane: END *****
    ');
    
    % Calculation of Frequency Response:
    [db_s, mag_s, pha_s, ww_s] = freqs_m(cs, ds, 8);
    
    % Calculation of Impulse Response:
    [ha, x, t] = impulse(cs, ds);
    
    
    % Impulse Invariance Transformation:
    [b, a] = imp_invr(cs, ds, T); [C, B, A] = dir2par(b, a)
    
    % Calculation of Frequency Response:
    [db, mag, pha, grd, ww] = freqz_m(b, a);
    
    
    %% -----------------------------------------------------------------
    %%                             Plot
    %% -----------------------------------------------------------------  
    figure('NumberTitle', 'off', 'Name', 'Problem 8.21 Analog Chebyshev-I lowpass')
    set(gcf,'Color','white'); 
    M = 1.0;                          % Omega max
    
    subplot(2,2,1); plot(ww_s, mag_s/T);  grid on; %axis([-10, 10, 0, 1.2]);
    xlabel(' Analog frequency in kHz units'); ylabel('|H|'); title('Magnitude in Absolute');
    set(gca, 'XTickMode', 'manual', 'XTick', [-8, -3.8, -3.2, 0, 3.2, 3.8, 8]);
    set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.006, 0.94, 1]);
    
    subplot(2,2,2); plot(ww_s, db_s);  grid on; %axis([0, M, -50, 10]);
    xlabel('Analog frequency in kHz units'); ylabel('Decibels'); title('Magnitude in dB ');
    set(gca, 'XTickMode', 'manual', 'XTick', [-8, -3.8, 0, 3.2, 3.8, 8]);
    set(gca, 'YTickMode', 'manual', 'YTick', [-45, -1, 0]);
    set(gca,'YTickLabelMode','manual','YTickLabel',['45';' 1';' 0']);
    
    subplot(2,2,3); plot(ww_s, pha_s/pi);  grid on; axis([-10, 10, -1.2, 1.2]);
    xlabel('Analog frequency in kHz nuits'); ylabel('radians'); title('Phase Response');
    set(gca, 'XTickMode', 'manual', 'XTick', [-8, -3.8, 0, 3.2, 3.8, 8]);
    set(gca, 'YTickMode', 'manual', 'YTick', [-1:0.5:1]);
    
    
    subplot(2,2,4); plot(t, ha); grid on; %axis([0, 30, -0.05, 0.25]); 
    xlabel('time in seconds'); ylabel('ha(t)'); title('Impulse Response');
    
    
    
    
    figure('NumberTitle', 'off', 'Name', 'Problem 8.21 Digital Chebyshev-I lowpass')
    set(gcf,'Color','white'); 
    M = 2;                          % Omega max
    
    subplot(2,2,1); plot(ww/pi, mag); axis([0, M, 0, 1.2]); grid on;
    xlabel(' frequency in pi units'); ylabel('|H|'); title('Magnitude Response');
    set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.8, 0.95, M]);
    set(gca, 'YTickMode', 'manual', 'YTick', [0, 0.0056, 0.9441, 1]);
    
    subplot(2,2,2); plot(ww/pi, pha/pi); axis([0, M, -1.1, 1.1]); grid on;
    xlabel('frequency in pi nuits'); ylabel('radians in pi units'); title('Phase Response');
    set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.8, 0.95, M]);
    set(gca, 'YTickMode', 'manual', 'YTick', [-1:1:1]);
    
    subplot(2,2,3); plot(ww/pi, db); axis([0, M, -30, 10]); grid on;
    xlabel('frequency in pi units'); ylabel('Decibels'); title('Magnitude in dB ');
    set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.8, 0.95, M]);
    set(gca, 'YTickMode', 'manual', 'YTick', [-60, -45, -1, 0]);
    set(gca,'YTickLabelMode','manual','YTickLabel',['60';'45';' 1';' 0']);
    
    subplot(2,2,4); plot(ww/pi, grd); grid on; %axis([0, M, 0, 35]);
    xlabel('frequency in pi units'); ylabel('Samples'); title('Group Delay');
    set(gca, 'XTickMode', 'manual', 'XTick', [0, 0.8, 0.95, M]);
    %set(gca, 'YTickMode', 'manual', 'YTick', [0:5:35]);
    
    figure('NumberTitle', 'off', 'Name', 'Problem 8.21 Pole-Zero Plot')
    set(gcf,'Color','white'); 
    zplane(b,a); 
    title(sprintf('Pole-Zero Plot'));
    %pzplotz(b,a);
    
    
    
    % ----------------------------------------------
    %       Calculation of Impulse Response
    % ----------------------------------------------
    figure('NumberTitle', 'off', 'Name', 'Problem 8.21 Imp & Freq Response')
    set(gcf,'Color','white'); 
    t = [0:0.01:60]; subplot(2,1,1); impulse(cs,ds,t); grid on;   % Impulse response of the analog filter
    axis([0,60,-0.5,1.0]);hold on
    
    n = [0:1:60/T]; hn = filter(b,a,impseq(0,0,60/T));           % Impulse response of the digital filter
    stem(n*T,hn); xlabel('time in sec'); title (sprintf('Impulse Responses T=%2d',T));
    hold off
    
    % Calculation of Frequency Response:
    [dbs, mags, phas, wws] = freqs_m(cs, ds, 2*pi/T);             % Analog frequency   s-domain  
    
    [dbz, magz, phaz, grdz, wwz] = freqz_m(b, a);                 % Digital  z-domain
    
    %% -----------------------------------------------------------------
    %%                             Plot
    %% -----------------------------------------------------------------  
    
    subplot(2,1,2); plot(wws/(2*pi),mags/T,'b+', wwz/(2*pi*T),magz,'r'); grid on;
    
    xlabel('frequency in Hz'); title('Magnitude Responses'); ylabel('Magnitude'); 
    
    text(-0.8,0.15,'Analog filter'); text(0.6,1.05,'Digital filter');
    

      运行结果:

            通带、阻带指标

            模拟Chebyshev-1型低通系统函数,串联形式系数

             脉冲响应不变法,转换成数字低通,系统函数直接形式系数

            模拟Chebyshev-1型低通,幅度谱、相位谱和脉冲响应

            数字Chebyshev-1型低通,幅度谱、相位谱和群延迟

  • 相关阅读:
    [Go] 写文件和判断文件是否存在
    [日常] 解决github速度特别慢
    [Go] imap收信非并发
    [Linux] 使用secureCRT实现SSH隧道服务器端口转发到本机内网穿透
    [Linux] 解决nginx: [emerg] directive "rewrite" is not terminated by ";"
    [MySQL] 解决Error 1698: Access denied for user 'root'@'localhost'
    [Go] gocron源码阅读-判断是否使用root用户执行
    [日常] 前端资源测试机上忽略版本号的的nginx配置
    [Go] 使用go mod安装beego
    [Go] tcp服务下的数据传递
  • 原文地址:https://www.cnblogs.com/ky027wh-sx/p/11118447.html
Copyright © 2011-2022 走看看