EE342.01: MATLAB M-FILE DEMONSTRATING dft() FUNCTION FOR COMPUTING DFT

MATLAB M-File example15.m:
%
% Filename: example15.m
%
% Description: m-file demonstrating the dft() function for computing
%              the DFT of x[n]
%

clear;                      % clear matlab memory

xn = [2 1 2 1];             % define DT signal x[n]
N = length(xn);             % number of data points

Xk = dft(xn);               % computed DFT Xk of x[n]

subplot(2,1,1);             % plot magnitude spectra
stem(0:N-1,abs(Xk),'filled');
xlabel('k'); ylabel('|X_k|');
title('Magnitude Spectra from DFT');

subplot(2,1,2);             % plot phase spectra
stem(0:N-1,angle(Xk)*180/pi,'filled');
xlabel('k'); ylabel('Angle(X_k) ');
title('Phase Spectra from DFT ');
MATLAB Plot Generated: