example5_4.m

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

M
37
字号
%==========================================================================
%  Name:example5_4.m
%  The program compute the DTFT of discrete-time sequence x(n),
%  and plot the curves.
%==========================================================================
clear;close all;
n=-20:20;
x=input('Type in the time sequence x[n]=');%u(n)-u(n-1);
w1=2*pi;N=512;k=-N:N;
dw=w1/N;
w=k*w1/(N);
X=x*exp(-j*n'*w);   % Compute the Fourier transform of x[n]
X1=abs(X);
phi=57.3*angle(X);

k=input('Type in the scale k=');
X2=X.*(u(w+pi*k)-u(w-pi*k));
x1=X2*dw*exp(j*w'*n)/(2*pi);  % Compute the inverse Fourier transform

subplot(221);stem(n,x,'.');
grid on;
title('The sequence x[n]');
axis([-20,20,-0.2,1.2])

subplot(222);plot(w/(pi),X1);grid on;
title('The DTFT of sequence x[n]');
axis([-2,2,-0.2,1.2])

subplot(223);stem(n,x1,'.');
xlabel('Index n');grid on;
axis([-20,20,-0.2,1.2])

subplot(224);
plot(w/(pi),abs(X2),'r');grid on;
xlabel('w[*pi]');
axis([-2,2,-0.2,1.2])

⌨️ 快捷键说明

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