zoukankan      html  css  js  c++  java
  • DSP using MATLAB 示例 Example3.19

    代码:

    % Analog Signal
    Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t));
    
    % Discrete-time Signal
    Ts = 0.0002; n = -25:1:25; x = exp(-1000*abs(n*Ts));
    
    % Discrete-time Fourier Transform
    %Wmax = 2*pi*2000; 
    K = 500; k = 0:1:K; w = pi*k/K;                 % index array k for frequencies
    X = x * exp(-j*n'*w); 
    
    magX  = abs(X);  angX  = angle(X);  realX  = real(X);  imagX  = imag(X);
    %% --------------------------------------------------------------------
    %%              START X's  mag ang real imag
    %% --------------------------------------------------------------------
    figure('NumberTitle', 'off', 'Name', 'Example3.19a X its mag ang real imag');
    set(gcf,'Color','white'); 
    subplot(2,2,1); plot(w/pi,magX); grid on;  %axis([0,1,0,1.5]); 
    title('Magnitude Response');
    xlabel('frequency in pi units'); ylabel('Magnitude  |X|'); 
    subplot(2,2,3); plot(w/pi, angX/pi); grid on; % axis([-1,1,-1,1]);
    title('Phase Response');
    xlabel('frequency in pi units'); ylabel('Radians/pi');
    
    subplot('2,2,2'); plot(w/pi, realX); grid on;
    title('Real Part');
    xlabel('frequency in pi units'); ylabel('Real');
    subplot('2,2,4'); plot(w/pi, imagX); grid on;
    title('Imaginary Part');
    xlabel('frequency in pi units'); ylabel('Imaginary');
    %% -------------------------------------------------------------------
    %%             END X's  mag ang real imag
    %% -------------------------------------------------------------------
    
    
    
    
    X = real(X);
    
    w = [-fliplr(w), w(2:K+1)];                     % Omega from -Wmax to Wmax
    X = [fliplr(X), X(2:K+1)];                      % X over -Wmax to Wmax interval
    %% --------------------------------------------------------------------
    %%              
    %% --------------------------------------------------------------------
    figure('NumberTitle', 'off', 'Name', '<<DSP MATLAB>> Example3.19a');
    set(gcf,'Color','white'); 
    subplot(2,1,1); plot(t*1000,xa); grid on;  %axis([0,1,0,1.5]); 
    title('Discrete Signal');
    xlabel('t in msec units.'); ylabel('x1(n)'); hold on;
    stem(n*Ts*1000,x); gtext('Ts=0.2 msec'); hold off;
    
    subplot(2,1,2); plot(w/pi, X); grid on; % axis([-1,1,-1,1]);
    title('Discrete-time Fourier Transform');
    xlabel('frequency in pi units'); ylabel('X1(w)');
    
    %% -------------------------------------------------------------------
    %%           
    %% -------------------------------------------------------------------
    

      运行结果:

    代码:

    % Analog Signal
    Dt = 0.00005; t = -0.005:Dt:0.005; xa = exp(-1000*abs(t));
    
    % Discrete-time Signal
    %Ts = 0.0002; n = -25:1:25; x = exp(-1000*abs(n*Ts));
    Ts = 0.001; n = -5:1:5; x = exp(-1000*abs(n*Ts));
    
    % Discrete-time Fourier Transform
    %Wmax = 2*pi*2000; 
    K = 500; k = 0:1:K; w = pi*k/K;                 % index array k for frequencies
    X = x * exp(-j*n'*w); 
    
    magX  = abs(X);  angX  = angle(X);  realX  = real(X);  imagX  = imag(X);
    %% --------------------------------------------------------------------
    %%              START X's  mag ang real imag
    %% --------------------------------------------------------------------
    figure('NumberTitle', 'off', 'Name', 'Example3.19b X its mag ang real imag');
    set(gcf,'Color','white'); 
    subplot(2,2,1); plot(w/pi,magX); grid on;  %axis([0,1,0,1.5]); 
    title('Magnitude Response');
    xlabel('frequency in pi units'); ylabel('Magnitude  |X|'); 
    subplot(2,2,3); plot(w/pi, angX/pi); grid on; % axis([-1,1,-1,1]);
    title('Phase Response');
    xlabel('frequency in pi units'); ylabel('Radians/pi');
    
    subplot('2,2,2'); plot(w/pi, realX); grid on;
    title('Real Part');
    xlabel('frequency in pi units'); ylabel('Real');
    subplot('2,2,4'); plot(w/pi, imagX); grid on;
    title('Imaginary Part');
    xlabel('frequency in pi units'); ylabel('Imaginary');
    %% -------------------------------------------------------------------
    %%             END X's  mag ang real imag
    %% -------------------------------------------------------------------
    
    
    
    
    X = real(X);
    
    w = [-fliplr(w), w(2:K+1)];                     % Omega from -Wmax to Wmax
    X = [fliplr(X), X(2:K+1)];                      % X over -Wmax to Wmax interval
    %% --------------------------------------------------------------------
    %%              
    %% --------------------------------------------------------------------
    figure('NumberTitle', 'off', 'Name', '<<DSP MATLAB>> Example3.19b');
    set(gcf,'Color','white'); 
    subplot(2,1,1); plot(t*1000,xa); grid on;  %axis([0,1,0,1.5]); 
    title('Discrete Signal');
    xlabel('t in msec units.'); ylabel('x1(n)'); hold on;
    stem(n*Ts*1000,x); gtext('Ts=0.1 msec'); hold off;
    
    subplot(2,1,2); plot(w/pi, X); grid on; % axis([-1,1,-1,1]);
    title('Discrete-time Fourier Transform');
    xlabel('frequency in pi units'); ylabel('X1(w)');
    
    %% -------------------------------------------------------------------
    %%           
    %% -------------------------------------------------------------------
    

      运行结果:

    牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
  • 相关阅读:
    Android kotlin jsoup解析网页html代码
    Android kotlin 判断网络状态
    ASP.NET设计模式笔记1
    C# SMTP发送邮件
    SQL连接数和CPU使用情况查询
    Grafana笔记
    Docker笔记
    solidity学习(四)---storage和memory关键字
    e-book
    solidity学习(四)-- Require(), Assert(), Revert()的用法和区别
  • 原文地址:https://www.cnblogs.com/ky027wh-sx/p/6087767.html
Copyright © 2011-2022 走看看