You are on page 1of 3

EXPERIMENT – 4

AIM: Write your own MATLAB function to compute DFT (Discrete Fourier Transform) and IDFT
(Inverse Discrete Fourier Transform) for the spectral analysis of signals.

1. Find the DFT-transform of the following signals x(n)={1,2,3,2}

SCRIPT
x = [1 2 3 2];
N = length(x);
w = exp(-(1i)*2*pi/N);
W = w*ones(N);
temp = [0:N-1];
powmat = temp'*temp;
W = W.^powmat;

X = W*x';
clc;
disp(‘x(n)’); disp(x)
disp(‘X(k)’); disp(X’);
COMMAND WINDOW
>> x(n)
>> 1.00 2.00 3.00 2.00
>> X(k)
>> 8.0000 + 0.0000i -2.0000 + 0.0000i 0.0000 + 0.0000i -2.0000 + 0.0000i

2. Find the IDFT of X(K)={4,2,0,4}

SCRIPT
X = [4 2 0 4];
N = length(X);
w = exp(-(1i)*2*pi/N);
W = w*ones(N);
temp = [0:N-1];
powmat = temp'*temp;
W = W.^powmat;

x = (1/N)*(conj(W)*X');
clc;
disp(‘x(n)’); disp(x)
disp(‘X(k)’); disp(X’);
COMMAND WINDOW

>> x(n)
>> 2.5000 + 0.0000i 1.0000 - 0.5000i -0.5000 + 0.0000i 1.0000 + 0.5000i
>> X(k)
>> 4 2 0 4
3. Find the DFT-transform of the following signals x(n)={1,1,0,0,0,0,0,0}

SCRIPT
x = [1 1 0 0 0 0 0 0];
N = length(x);
w = exp(-(1i)*2*pi/N);
W = w*ones(N);
temp = [0:N-1];
powmat = temp'*temp;
W = W.^powmat;

X = W*x';
clc;
disp(‘x(n)’); disp(x)
disp(‘X(k)’); disp(X’);
COMMAND WINDOW

>> x(n)
>> 1 1 0 0 0 0 0 0
>> X(k)
>> Columns 1 through 5
2.0000 + 0.0000i 1.7071 + 0.7071i 1.0000 + 1.0000i 0.2929 + 0.7071i
0.0000 + 0.0000i

Columns 6 through 8
0.2929 - 0.7071i 1.0000 - 1.0000i 1.7071 - 0.7071i

4. Find the IDFT of X(K)={1,0,1,0}

SCRIPT
X = [1 0 1 0];
N = length(X);
w = exp(-(1i)*2*pi/N);
W = w*ones(N);
temp = [0:N-1];
powmat = temp'*temp;
W = W.^powmat;

x = (1/N)*(conj(W)*X');
clc;
disp(‘x(n)’); disp(x)
disp(‘X(k)’); disp(X’);

COMMAND WINDOW
>> x(n)
>> 0.5000 + 0.0000i
0.0000 + 0.0000i
0.5000 - 0.0000i
0.0000 + 0.0000i
>> X(k)
>> 4 2 0 4

2 | EXPERIMENT 4
3 | EXPERIMENT 4

You might also like