dtft_beike.m

来自「经典《信号与系统》教程的matlab例程,对深入理解信号与系统相关概念有很大帮助」· M 代码 · 共 62 行

M
62
字号
%==========================================================================
%  Name:DTFT.m
%  The program compute the DTFT of discrete-time sequence x(n),
%  and plot the curves.
%==========================================================================
clear;
n=-5:5;
x1=0.5.^n.*u(n);
x2=0.5.^(-n).*u(-n);
x3=(x1+x2)/2;
x4=(x1-x2)/2;

W1=2*pi;                           
N=512;           
k=-N:N;                              
W=k*W1/(N); 

figure(1)
F1=x1*exp(-j*n'*W);                  
F1_1=abs(F1);                           
phi=57.3*angle(F1);                     

subplot(3,1,1);stem(n,x1,'.');grid on;
ylabel('the curve of x(n)');
title('The DTFT of the sequence x(n)');
subplot(3,1,2);plot(W,F1_1);grid on;
xlabel('w');
ylabel('The magnitude spectra ');
subplot(3,1,3);
plot(W,phi,'r');grid on;
xlabel('w');ylabel('The phase spectra');

figure(2)
F2=x3*exp(-j*n'*W);                  
F2_2=real(F2);                           
phi=57.3*angle(F2);                     

subplot(3,1,1);stem(n,x3,'.');grid on;
ylabel('the curve of x(n)');
title('The DTFT of the sequence x(n)');
subplot(3,1,2);plot(W,F2);grid on;
xlabel('w');
ylabel('The magnitude spectra ');
subplot(3,1,3);
plot(W,phi,'r');grid on;
xlabel('w');ylabel('The phase spectra');

figure(3)
F3=x4*exp(-j*n'*W);                  
F3_3=imag(F3);                           
phi=57.3*angle(F3);                     

subplot(3,1,1);stem(n,x4,'.');grid on;
ylabel('the curve of x(n)');
title('The DTFT of the sequence x(n)');
subplot(3,1,2);plot(W,F3_3);grid on;
xlabel('w');
ylabel('The magnitude spectra ');
subplot(3,1,3);
plot(W,phi,'r');grid on;
xlabel('w');ylabel('The phase spectra');

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?