DFT AND IDFT OF A SEQUENCE
Aim: To find out the DFT and IDFT of a sequence
Theory:
DFT:
N 1 N 1
X ( k ) x ( n )e j 2kn / N
x(n) e j 2 / N
nk
n 0 n 0
WN e j 2 / N
N 1
X (k ) x(n)WN nk
n0
Inverse DFT:
N 1
1
x ( n)
N
X ( k )e
k 0
j 2nk / N
Matlab code:
%find the DFT and IDFT of the sequence
clear all;
close all;
x=input('enter the sequence');
N=input('enter N-point DFT');
for k=1:N
X(k)=0;
for n=1:N
X(k)=X(k)+x(n)*exp(-j*2*pi*(k-1)*(n-1)/N)
end
end
X=double(X);
figure(1);
subplot(3,2,1)
stem(abs(X));
xlabel('k')
ylabel('Magnitude |X(k)|')
title('Magnitude plot of DFT X(k) (without using function)')
subplot(3,2,3)
stem(angle(X));
xlabel('k')
ylabel('Angle of X(k)')
title('Phase plot of DFT X(k)')
for n=1:N
x1(n)=0;
for k=1:N
x1(n)=x1(n)+X(k)*exp(j*2*pi*(k-1)*(n-1)/N)/N;
end
end
subplot(3,2,5)
stem(real(x1));
xlabel('n')
ylabel('Amplitude')
title('IDFT of X(k)')
X1=fft(x,N);
subplot(3,2,2)
stem(abs(X1));
xlabel('k')
ylabel('Magnitude |X(k)|')
title('Magnitude plot of DFT X(k) (Using fucntion)')
subplot(3,2,4)
stem(angle(X1));
xlabel('k')
ylabel('Angle of X(k)')
title('Phase plot of DFT X(k)')
x2=ifft(X1,N)
subplot(3,2,6)
stem(x2);
xlabel('n')
ylabel('Amplitude')
title('IDFT of X(k)')
Output:
enter the sequence[1 2 3 1 0 0 0 0]
enter N-point DFT 8
X =
Columns 1 through 4
7.0000 1.7071 - 5.1213i -2.0000 - 1.0000i 0.2929 + 0.8787i
Columns 5 through 8
1.0000 + 0.0000i 0.2929 - 0.8787i -2.0000 + 1.0000i 1.7071 + 5.1213i
x2 =
1.0000 2.0000 3.0000 1.0000 0 -0.0000 0 -
0.0000