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

            代码:

    %% ------------------------------------------------------------------------
    %%            Output Info about this m-file
    fprintf('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 8.1 
    
    ');
    banner();
    %% ------------------------------------------------------------------------
    
    % digital resonator
    %r = 0.8
    %r = 0.9
    r = 0.99
    omega0 = pi/4;
    
    % corresponding system function  Direct form
    b0 = (1-r)*sqrt(1+r*r-2*r*cos(2*omega0));     % gain parameter
    b = [b0  0  0];                               % denominator                      
    a = [1 -2*r*cos(omega0) r*r];                 % numerator
    
    % precise resonant frequency and 3dB bandwidth
    omega_r = acos((1+r*r)*cos(omega0)/(2*r));
    delta_omega = 2*(1-r);
    fprintf('
    Resonant Freq is : %.4fpi unit, 3dB bandwidth is %.4f 
    ', omega_r/pi,delta_omega);
    % 
    
    [db, mag, pha, grd, w] = freqz_m(b, a);
    
    figure('NumberTitle', 'off', 'Name', 'Problem 8.1 Digital Resonator')
    set(gcf,'Color','white'); 
    
    subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -60 10]); 
    set(gca,'YTickMode','manual','YTick',[-60,-30,0])
    set(gca,'YTickLabelMode','manual','YTickLabel',['60';'30';' 0']);
    set(gca,'XTickMode','manual','XTick',[0,0.25,0.5,1,1.5,1.75]);
    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.25,1,1.75,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');
    set(gca,'XTickMode','manual','XTick',[0,0.25,1,1.75,2]);
    %set(gca,'YTickMode','manual','YTick',[0,1.0]);
    
    figure('NumberTitle', 'off', 'Name', 'Problem 8.1 Pole-Zero Plot')
    set(gcf,'Color','white'); 
    zplane(b,a); 
    title(sprintf('Pole-Zero Plot, r=%.2f  0.25\pi',r));
    %pzplotz(b,a);
    
    
    % Impulse Response
    fprintf('
    ----------------------------------');
    fprintf('
    Partial fraction expansion method: 
    ');
    [R, p, c] = residuez(b,a)
    MR = (abs(R))'              % Residue  Magnitude
    AR = (angle(R))'/pi         % Residue  angles in pi units
    Mp = (abs(p))'              % pole  Magnitude
    Ap = (angle(p))'/pi         % pole  angles in pi units
    [delta, n] = impseq(0,0,40);
    h_chk = filter(b,a,delta);      % check sequences
    
    %h = 2*0.1281* ( (0.5657*1.414) .^n) .* (cos(pi*n/4) + sin(pi*n/4));     % r=0.8
    %h = 2*0.0673* ( (0.6364*1.414) .^n) .* (cos(pi*n/4) + sin(pi*n/4));     % r=0.9
    h = 2*0.0070* ( (0.7000*1.414) .^n) .* (cos(pi*n/4) + sin(pi*n/4));      % r=0.99
    
    
    figure('NumberTitle', 'off', 'Name', 'Problem 8.1 Digital Resonator, h(n) by filter and Inv-Z ')
    set(gcf,'Color','white'); 
    
    subplot(2,1,1); stem(n, h_chk); grid on; %axis([0 2 -60 10]); 
    xlabel('n'); ylabel('h\_chk'); title('Impulse Response sequences by filter');
    
    subplot(2,1,2); stem(n, h); grid on; %axis([0 1 -100 10]); 
    xlabel('n'); ylabel('h'); title('Impulse Response sequences by Inv-Z');
    
    
    [db, mag, pha, grd, w] = freqz_m(h, [1]);
    
    
    figure('NumberTitle', 'off', 'Name', 'Problem 8.1 Digital Resonator, h(n) by Inv-Z ')
    set(gcf,'Color','white'); 
    
    subplot(2,2,1); plot(w/pi, db); grid on; axis([0 2 -60 10]); 
    set(gca,'YTickMode','manual','YTick',[-60,-30,0])
    set(gca,'YTickLabelMode','manual','YTickLabel',['60';'30';' 0']);
    set(gca,'XTickMode','manual','XTick',[0,0.25,0.5,1,1.5,1.75]);
    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.25,1,1.75,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');
    set(gca,'XTickMode','manual','XTick',[0,0.25,1,1.75,2]);
    %set(gca,'YTickMode','manual','YTick',[0,1.0]);
    

      运行结果:

            系统函数部分分式展开,

            零极点的模和幅角:

            用脉冲序列当输入得到脉冲响应序列h_chk(n),系统函数H(z)取逆z变换得h(n),二者如下图

            h_chk(n)的幅度谱、相位谱、群延迟

            h(n)的幅度谱、相位谱、群延迟

            r=0.9、0.99的图这里就不放了。

    牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
  • 相关阅读:
    拓扑排序
    数论初步(费马小定理)
    HDU
    HDU
    八月馒头
    萌新仓鼠,参上!
    新姿势
    字典树
    HDU
    Codeforce
  • 原文地址:https://www.cnblogs.com/ky027wh-sx/p/10927306.html
Copyright © 2011-2022 走看看