《DSP using MATLAB》Problem 5.36

本文通过MATLAB实现离散傅立叶变换(DFT),针对一个正弦序列进行分析,展示其幅值、相位及实虚部分的特性,并提供完整的代码与运行结果。

        第1小题

        代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%%            Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf('        <DSP using MATLAB> Problem 5.36 \n\n');

banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

% -------------------------------------------------------------------------------------
%          X(k) is DFTs of real-valued sequence x(n)             
%           x(n)=A*sin(2*pi*l*n/N)      n=[0:N-1]
%             
%             1   x1(n) = 3sin(0.04*pi*n)  n=[0:200-1]                                     
% -------------------------------------------------------------------------------------
N = 200; l = 2;
n1 = [0:N-1];
x1 = 3*sin(2*pi*l*n1/100);

figure('NumberTitle', 'off', 'Name', 'P5.36.1 x(n), N=200')
set(gcf,'Color','white'); 
stem(n1, x1); 
xlabel('n'); ylabel('x(n)');
title('x(n)=3sin(0.04\pin)');  grid on;

    k1 = [0:N-1];
Xk_DFT = fft(x1, N);
    N1 = length(Xk_DFT);                                              % length 

    magXk_DFT = abs( [ Xk_DFT ] );                                    % DFT magnitude
    angXk_DFT = angle( [Xk_DFT] )/pi;                                 % DFT angle
   realXk_DFT = real(Xk_DFT); imagXk_DFT = imag(Xk_DFT);

figure('NumberTitle', 'off', 'Name', 'P5.36.1 X(k), DFT of x(n) N=200')
set(gcf,'Color','white'); 
subplot(2,2,1); stem(k1, magXk_DFT); 
xlabel('k'); ylabel('magnitude(k)');
title('magnitude DFT of x(n)');  grid on;
subplot(2,2,3); stem(k1, angXk_DFT);  
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('angle(k)');
title('angle DFT of x(n)');  grid on;
subplot(2,2,2); stem(k1, realXk_DFT); 
xlabel('k'); ylabel('real (k)');
title('real DFT of x(n)');  grid on;
subplot(2,2,4); stem(k1, imagXk_DFT);  
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('k'); ylabel('imag (k)');
title('imag DFT of x(n)');  grid on;


figure('NumberTitle', 'off', 'Name', 'P5.36.1 Imagnary X(k), N=200')
set(gcf,'Color','white'); 
stem(k1, imagXk_DFT); 
xlabel('k'); ylabel('imag (k)');
title('imag DFT of x(n)');  grid on;

  运行结果:

        200个样点包含4个周期,

        序列的DFT

        DFT序列的虚部,范围[0:N-1]。

        DFT序列的实部和虚部,范围[-N:N-1]。

         DFT序列的实部和虚部,范围[-N/2:N/2-1]。

 

转载于:https://www.cnblogs.com/ky027wh-sx/p/9513412.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值