• 《DSP using MATLAB》Problem 5.4


    代码:

    %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    %%            Output Info about this m-file
    fprintf('
    ***********************************************************
    ');
    fprintf('        <DSP using MATLAB> Problem 5.4 
    
    ');
    
    banner();
    %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    
    % ------------------------------------------
    %  1  x1(n)=5sin(0.1pi*n)   n=[0:19], N=40
    % ------------------------------------------
    L = 20; n = [0:L-1]; N = 40; k1 = [0 : N-1];             % wave parameters
    %k2 = [-(N-1):0];
    xn_1 = [5*sin(0.1*pi*n), zeros(1, N-L)];
    Xk_1 = dfs(xn_1, N);                                     % DFS
    magXk = abs( [ Xk_1(1 : N)] );        % DFS magnitude
    angXk = angle( Xk_1 )/pi;             % DFS angle
    
    xn_2 = [xn_1(1:20) -xn_1(1:20)];
    Xk_2 = dfs(xn_2, N);
    magXk_2 = abs( [Xk_2(1:N)]);
    angXk_2 = angle( Xk_2)/pi;
    
    figure('NumberTitle', 'off', 'Name', 'P5.4 xn_1 and xn_2')
    set(gcf,'Color','white'); 
    subplot(2,1,1); stem([0:N-1], xn_1);
    xlabel('n'); ylabel('x(n)');
    title('xn1 sequence in Problem 5.3, N=40');  grid on;
    subplot(2,1,2); stem([0:N-1], xn_2);
    xlabel('n'); ylabel('x(n)');
    title('xn2 sequence, N=40');  grid on;
    
    
    %% ------------------------------------------------------
    %%                 DFS(k) of xn1 sequence
    %% ------------------------------------------------------
    figure('NumberTitle', 'off', 'Name', 'P5.4 DFS(k) of xn_1')
    set(gcf,'Color','white'); 
    subplot(2,1,1); stem(k1, magXk); %axis([-N/2, N/2, -0.5, 50.5]);
    xlabel('k'); ylabel('magnitude(k)');
    title('DFS magnitude of xn1, N=40');  grid on;
    subplot(2,1,2); stem(k1, angXk); %axis([-N/2, N/2, -0.5, 50.5]);
    xlabel('k'); ylabel('angle(k)');
    title('DFS angle of xn1, N=40');  grid on;
    
    
    %% ------------------------------------------------------
    %%                 DFS(k) of xn2 sequence
    %% ------------------------------------------------------
    figure('NumberTitle', 'off', 'Name', 'P5.4 DFS(k) of xn_2')
    set(gcf,'Color','white'); 
    subplot(2,1,1); stem(k1, magXk_2); %axis([-N/2, N/2, -0.5, 50.5]);
    xlabel('k'); ylabel('magnitude(k)');
    title('DFS magnitude of xn2, N=40');  grid on;
    subplot(2,1,2); stem(k1, angXk_2); %axis([-N/2, N/2, -0.5, 50.5]);
    xlabel('k'); ylabel('angle(k)');
    title('DFS angle of xn2, N=40');  grid on;
    

      运行结果:

            上面是从0到N-1范围内的图形。还可以得到[-N/2,N/2]范围内的。

    牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
  • 相关阅读:
    codeforces C. No to Palindromes!
    codeforces D. Pashmak and Parmida's problem
    codeforces C. Little Pony and Expected Maximum
    codeforces D. Count Good Substrings
    codeforces C. Jzzhu and Chocolate
    codeforces C. DZY Loves Sequences
    codeforces D. Multiplication Table
    codeforces C. Painting Fence
    hdu 5067 Harry And Dig Machine
    POJ 1159 Palindrome
  • 原文地址:https://www.cnblogs.com/ky027wh-sx/p/9282547.html
Copyright © 2020-2023  润新知