Thursday, September 15, 2011

Discrete Fourier Transform & Inverse Discrete Transform (DFT AND IDFT)


3. Discrete Fourier Transform & Inverse Discrete Transform (DFT AND IDFT)



AIM: To develop a program for Computing DFT and IDFT in MATLAB

REQUIREMENTS: MATLAB 7.5

Learning Objectives: To make the students familiar with concept of DFT and IDFT with
the use of MATLAB.

THEORY: The discrete Fourier transform (DFT) X[k] of a finite-length sequence x[n] can be
easily computed in MATLAB using the function fft. There are two versions of this function.
fft(x) computes the DFT X[k] of the sequence x[n] where the length of X[k] is the same as that of
x[n]. fft(x,L) computes the L-point DFT of a sequence x[n] of length N where L = N. If L > N,
x[n] is zero-padded with L-N trailing zero-valued samples before the DFT is computed. The
inverse discrete Fourier transform (IDFT) x[n] of a DFT sequence X[k] can likewise be computed
using the function ifft, which also has two versions.

ALGORITHM (For DFT):
1 Enter the input Sequence ,x having length=4
2 Set the range of k according to the length of x.
3 Computing DFT, store the value in X(k).
4 Plotting the DFT of given Sequence,store in X(k).

PROGRAM CODE:
% Program to perform Discrete Fourier Transform:
clc;
clear all;
close all hidden;
x=input('The given i/p sequence is x(n): ');
subplot(2,2,[1,2]), stem(x);
title('i/p sequencce x(n)is:');
xlabel('---->n');
ylabel('---->x(n)');grid;
N=length(x);
for k=1:N
X(k)=0;
for n=1:N
X(k)=X(k)+x(n).*exp(-j.*2.*pi.*(n-1).*(k-1)./N);
end
end
disp('The DFT of the i/p sequence x(n) is X(n):')
p=0:(N-1);
subplot(2,2,[3,4]), stem(p,abs(X));
title('The DFT of the i/p sequence x(n) is X(n):');
xlabel('---->n');
 ylabel('---->X(n)');grid;
disp(X);

ALGORITHM (For IDFT):

1 Enter the input Sequence, x having length=4
2 Set the range of k according to the length of x.
3 Computing IDFT, store the value in X(k).
4 Plotting the IDFT of given Sequence, store in X(k).

% Program to perform Inverse Discrete Fourier Transform:
clc;
clear all;
close all hidden;
X=input('The given i/p sequence is X(n): ');
subplot(2,2,[1,2]), stem(X);
title('i/p sequencce X(n)is:');
xlabel('---->n');
ylabel('---->X(n)');grid;
N=length(X);
for n=1:N
x(n)=0;
for k=1:N
x(n)=x(n)+X(k).*exp(j.*2.*pi.*(n-1).*(k-1)./N);
x(n)=x(n)./N;
end
end
disp('The IDFT of the i/p sequence X(n) is x(n):')
p=0:(N-1);
subplot(2,2,[3,4]), stem(p,abs(x));
title('The IDFT of the i/p sequence X(n) is x(n):');
xlabel('---->n');
ylabel('---->x(n)');grid;
disp(x);

No comments:

Post a Comment