Lab_8
Lab_8
Signature:______________ Date:
Introduction:
The DFT is the most important discrete transform, used to perform Fourier analysis in many
practical applications. In digital signal processing, the function is any quantity or signal that
varies over time, such as the pressure of a sound wave, a radio signal, or
daily temperature readings, sampled over a finite time interval (often defined by a window
function). In image processing, the samples can be the values of pixels along a row or column of
a raster image. The DFT is also used to efficiently solve partial differential equations, and to
perform other operations such as convolutions or multiplying large integers.
THEORY:
The discrete Fourier transform, or DFT, is the primary tool of digital signal processing. The
foundation of Signal Processing Toolbox™ product is the fast Fourier transform (FFT), a method
for computing the DFT with reduced execution time. Many of the toolbox functions (including z-
domain frequency response, spectrum and cepstrum analysis, and some filter design and
implementation functions) incorporate the FFT.
The MATLAB® environment provides the functions fft and ifft to compute the discrete
Fourier transform and its inverse, respectively. For the input sequence x and its transformed
version X (the discrete-time Fourier transform at equally spaced frequencies around the unit
circle), the two functions implement the relationships
and
In these equations, the series subscripts begin with 1 instead of 0 because of the MATLAB
vector indexing scheme, and
Program for DFT:
xn=input('Enter the values of X[n] ='); % input from user
ln = length(xn); % length of input signal
xk= zeros(1,ln);% initial DFT vector
ixk=zeros(1,ln);
%calculate the DFT
for k=0:ln-1
for n=0:ln-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((-1i)*2*pi*k*n/ln));
end
end
%ploting the input signal
t=0:ln-1;
subplot(2,2,1)
stem(t,xn)
grid
title('input signal')
% ploting the magnitude plot
magnitude=abs(xk)
t=0:ln-1;
subplot(2,2,2)
stem(t,magnitude)
grid
title('imagnitude plot')
%ploting the phase plot
phase=angle(xk)
t=0:ln-1;
subplot(2,2,3)
stem(t,phase)
grid
title('phase plot')
% inverse DFT
for n=0:ln-1
for k=0:ln-1
ixk(k+1)=ixk(k+1)+(xk(n+1)*exp((1i)*2*pi*k*n/ln));
end
end
ixk=ixk./ln;
% ploting the inverse DFT
t=0:ln-1;
subplot(2,2,4)
stem(t,ixk)
grid
title('ploting inverse DFT')
Command window:
Enter the values of X[n] =[1 2 3]
magnitude =
phase =
0 2.6180 -2.6180
Output waveform:
2 4
1 2
0 0
0 0.5 1 1.5 2 0 0.5 1 1.5 2
2
2
0
1
-2
-4 0
0 0.5 1 1.5 2 0 0.5 1 1.5 2