dtft.m

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

M
37
字号
%==========================================================================
%  Name:DTFT.m
%  The program compute the DTFT of discrete-time sequence x(n),
%  and plot the curves.
%==========================================================================
clear;
p=input('1--close;2--open,please select the form of the sequence x(n):');
while p~=1&p~=2
    p=input('Please reselect the form of the sequence x(n):');
end
if p==1
   n=-10:10;
   f=input('Type in the expression of sequence x(n):');
end
if p==2
    f=input('Type in the vector of sequence x(n):');
    n=input('Type in the index of sequence x(n):');
end
W1=4*pi;                           
N=512;           
k=-N:N;                              
W=k*W1/(N);                            

F=f*exp(-j*n'*W);                  
F1=abs(F);                           
phi=57.3*angle(F);                     

subplot(221);stem(n,f,'.');grid on;
xlabel('Index n');title('the curve of x(n)');

subplot(222);plot(W,F1);grid on;
title('The DTFT of the sequence x(n)');
ylabel('The magnitude spectra ');
subplot(224);
plot(W,phi,'r');grid on;
xlabel('w');ylabel('The phase spectra');

⌨️ 快捷键说明

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