Sunteți pe pagina 1din 5

EXP 6 : DFT and IDFT

clc

clear all

N=input('the computation space: ')

xn=input('enter the sequence: ')

p=N-length(xn)

r=[xn,zeros(1,p)]

n=0:N-1

k=0:N-1

WN=exp((-j*2*pi)/N)

nk=n'*k
WNnk=WN.^nk

Xk=r*WNnk

n=0:N-1

k=0:N-1

WN=exp((j*2*pi)/N)

nk=n'*k

WNnk=WN.^nk

X=(Xk*WNnk)/N

t=0:N-1;

subplot(2,3,1);stem(t,xn);title('x(n)');xlabel('n');ylabel('amplitude');

subplot(2,3,2);stem(t,real(Xk));title('Real part of X(K)');xlabel('n');ylabel('amplitude');

subplot(2,3,3);stem(t,imag(Xk));title('Imaginary Part of X(K)');xlabel('n');ylabel('amplitude');


subplot(2,3,4);stem(t,abs(Xk));title('Magnitude Plot of X(K)');xlabel('n');ylabel('amplitude');

subplot(2,3,5);stem(t,angle(Xk));title('Phase plot of X(K)');xlabel('n');ylabel('amplitude');

subplot(2,3,6);stem(t,X);title('X(n)');xlabel('n');ylabel('amplitude');
x(n) Real part of X(K) Imaginary Part of X(K)
1 5 2.5

0.9 2
4
0.8 1.5

0.7 1
3
0.6 0.5
amplitude

amplitude
amplitude
0.5 2 0

0.4 -0.5
1
0.3 -1

0.2 -1.5
0
0.1 -2

0 -1 -2.5
0 2 4 6 8 0 2 4 6 8 0 2 4 6 8
n n n

Magnitude Plot of X(K) Phase plot of X(K) X(n)


5 2 1

4.5
1.5
0.8
4
1
3.5
0.6
0.5
3
amplitude

amplitude
amplitude

2.5 0 0.4

2
-0.5
0.2
1.5
-1
1
0
-1.5
0.5

0 -2 -0.2
0 2 4 6 8 0 2 4 6 8 0 2 4 6 8
n n n
x(n) Real part of X(K) Imaginary Part of X(K)
1 5 2.5

0.9 2
4
0.8 1.5

0.7 1
3
a m p lit u d e

a m p lit u d e

a m p lit u d e
0.6 0.5

0.5 2 0

0.4 -0.5
1
0.3 -1

0.2 -1.5
0
0.1 -2

0 -1 -2.5
0 2 4 6 8 0 2 4 6 8 0 2 4 6 8
n n n

Magnitude Plot of X(K) Phase plot of X(K) X(n)


5 2 1

4.5
1.5
0.8
4
1
3.5
0.6
a m p lit u d e

a m p lit u d e

a m p lit u d e
0.5
3

2.5 0 0.4

2
-0.5
0.2
1.5
-1
1
0
-1.5
0.5

0 -2 -0.2
0 2 4 6 8 0 2 4 6 8 0 2 4 6 8
n n n

S-ar putea să vă placă și