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

    代码:

    %% ------------------------------------------------------------------------
    %%            Output Info about this m-file
    fprintf('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 3.4 
    
    ');
    
    banner();
    %% ------------------------------------------------------------------------
    
    
    % ----------------------------------------------
    %            Rectangle Window sequence
    % ----------------------------------------------
    M = 101;
    
    n1_start = 0; n1_end = M;
    n1 = [n1_start : n1_end - 1]; 
    
    x1 =  ones(1, length(n1)); 
    
    figure('NumberTitle', 'off', 'Name', 'Problem 3.4 x1(n) Rectangle');
    set(gcf,'Color','white'); 
    stem(n1, x1); 
    xlabel('n'); ylabel('x1');  
    title(sprintf('x1(n) sequence, M = %d', M)); grid on;
    
    MM = 500;
    k = [-MM:MM];        % [-pi, pi]
    %k = [0:M];        % [0, pi]
    w = (pi/MM) * k;
    
    [X1] = dtft(x1, n1, w);                            
    
    magX1 = abs(X1); angX1 = angle(X1); realX1 = real(X1); imagX1 = imag(X1);
    
    
    figure('NumberTitle', 'off', 'Name', 'Problem 3.4 DTFT of Rm(n)'); 
    set(gcf,'Color','white');
    subplot(2,1,1); plot(w/pi, magX1/max(magX1)); grid on; 
    title('Magnitude Part');
    xlabel('frequency in pi units'); ylabel('Magnitude'); 
    subplot(2,1,2); plot(w/pi, angX1); grid on;
    title('Angle Part');
    xlabel('frequency in pi units'); ylabel('Radians');
    
    
    
    % --------------------------------------------------
    %                Hanning Window Sequence
    % --------------------------------------------------
    %n2_start = -9; n2_end = 15;
    %n2 = [n2_start : n2_end]; 
    n2 = n1;
    x2 = 0.5 * (1 - cos(2*pi*n1/(M-1))) .* x1; 
    
    figure('NumberTitle', 'off', 'Name', 'Problem 3.4 x2(n) Hanning');
    set(gcf,'Color','white'); 
    stem(n2, x2); 
    xlabel('n'); ylabel('x2');  
    title(sprintf('x2(n) sequence, M = %d', M)); grid on;
    
    
    MM = 500;
    k = [-MM:MM];        % [-pi, pi]
    %k = [0:M];        % [0, pi]
    w = (pi/MM) * k;
    
    [X2] = dtft(x2, n2, w);                            
    
    magX2 = abs(X2); angX2 = angle(X2); realX2 = real(X2); imagX2 = imag(X2);
    
    figure('NumberTitle', 'off', 'Name', 'Problem 3.4 DTFT of Cm(n)');; 
    set(gcf,'Color','white');
    subplot(2,1,1); plot(w/pi, magX2/max(magX2)); grid on; 
    title('Magnitude Part');
    xlabel('frequency in pi units'); ylabel('Magnitude'); 
    subplot(2,1,2); plot(w/pi, angX2); grid on;
    title('Angle Part');
    xlabel('frequency in pi units'); ylabel('Radians');
    
    
    % --------------------------------------------------
    %            Triangular Window Sequence
    % --------------------------------------------------
    %n3_start = -3; n3_end = 10;
    %n3 = [n3_start : n3_end]; 
    n3 = n1;
    x3 = (1 - abs(M-1-2*n3)/(M-1)) .* x1; 
    
    figure('NumberTitle', 'off', 'Name', 'Problem 3.4 x3(n) Triangular');
    set(gcf,'Color','white'); 
    stem(n3, x3); 
    xlabel('n'); ylabel('x3');  
    title(sprintf('x3(n) sequence, M = %d', M)); grid on;
    
    MM = 500;
    k = [-MM:MM];        % [-pi, pi]
    %k = [0:M];        % [0, pi]
    w = (pi/MM) * k;
    
    [X3] = dtft(x3, n3, w);                            
    
    magX3 = abs(X3); angX3 = angle(X3); realX3= real(X3); imagX3 = imag(X3);
    
    figure('NumberTitle', 'off', 'Name', 'Problem 3.4 DTFT of Tm(n)');; 
    set(gcf,'Color','white');
    subplot(2,1,1); plot(w/pi, magX3/max(magX3)); grid on; 
    title('Magnitude Part');
    xlabel('frequency in pi units'); ylabel('Magnitude'); 
    subplot(2,1,2); plot(w/pi, angX3); grid on;
    title('Angle Part');
    xlabel('frequency in pi units'); ylabel('Radians');
    
    
    % ---------------------------------------------
    %            Hamming Window sequence
    % ---------------------------------------------
    %n4_start = 0; n4_end = 50;
    %n4 = [n4_start : n4_end]; 
    n4 = n1;
    x4 = (0.54 - 0.46 * cos(2*pi*n4/(M-1))) .* x1; 
    
    figure('NumberTitle', 'off', 'Name', 'Problem 3.4 x4(n) Hamming');
    set(gcf,'Color','white'); 
    stem(n4, x4, 'filled'); 
    xlabel('n'); ylabel('x4');  
    title(sprintf('x4(n) sequence, M = %d', M)); grid on;
    
    MM = 500;
    k = [-MM:MM];        % [-pi, pi]
    %k = [0:M];        % [0, pi]
    w = (pi/MM) * k;
    
    [X4] = dtft(x4, n4, w);                            
    
    magX4 = abs(X4); angX4 = angle(X4); realX4= real(X4); imagX4 = imag(X4);
    
    figure('NumberTitle', 'off', 'Name', 'Problem 3.4 DTFT of Hm(n)');; 
    set(gcf,'Color','white');
    subplot(2,1,1); plot(w/pi, magX4/max(magX4)); grid on; 
    title('Magnitude Part');
    xlabel('frequency in pi units'); ylabel('Magnitude'); 
    subplot(2,1,2); plot(w/pi, angX4); grid on;
    title('Angle Part');
    xlabel('frequency in pi units'); ylabel('Radians');
    

      运行结果:

           矩形窗:

            汉宁窗:

            三角窗:

            汉明窗:

    牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
  • 相关阅读:
    计算机基础学习路线路线详情:4步骤·5门课
    python课程体系是怎么样的?
    老猿学5G扫盲贴:中国移动5G融合计费漫游计费架构和路由方案
    老猿学5G扫盲贴:中国移动网络侧CHF主要功能及计费处理的主要过程
    moviepy音视频剪辑:moviepy中的剪辑相关类及关系
    老猿学5G扫盲贴:与用户和终端相关的名词UE、SUPI、GPSI、PEI
    PyQt+moviepy音视频剪辑实战文章目录
    PyQt+moviepy音视频剪辑实战2:一个剪裁视频文件精华内容留存工具的实现
    PyQt+moviepy音视频剪辑实战2:实现一个剪裁视频文件精华内容留存工具
    PyQt+moviepy音视频剪辑实战1:多个音视频合成顺序播放或同屏播放的视频文件实现详解
  • 原文地址:https://www.cnblogs.com/ky027wh-sx/p/8053777.html
Copyright © 2011-2022 走看看