% Pregram to compute DFT and IDFT

clc
clf
clear all
xn=[1 1 0 0 ]
%Plotting input signal
subplot(4,1,1)
stem(xn)
xlabel('n->');
ylabel('x(n)->');
title('Input signal x(n)');
for k=1:4
freq=(-1j*2*pi*(k-1))/4;
wnk=exp(freq.*(0:3));
X(k)=sum(xn.*wnk)
end
%plotting magnitude of X(k)
subplot(4,1,2)
stem(abs(X));
xlabel('k->');
ylabel('magnitude of X(k)');
title('magnitude of X(k)');
%Plotting phase of X(k)
subplot(4,1,3)
stem(angle(X));
xlabel('k->');
ylabel('phaseof X(k)');
title('phase of X(k)');
for k=1:4
freq1=(j*2*pi*(k-1))/4;
wnk1=exp(freq1.*(0:3));
Z(k)=sum(X.*wnk1)
y(k)=Z(k)./4
end
%Plotting IDFT
subplot(4,1,4)
stem(abs(y))
xlabel('n->');
ylabel('y(n)->');
title('IDFT');

Sign up to vote on this title
UsefulNot useful