LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
Ex.No -4
Spectrum Analysis using Discrete Fourier Transform
Date: 13.09.2021
AIM:
To generate DFT for the given sequence using MATLAB program.
APPARATUS REQUIRED:
MATLAB , PC
THEORY:
The discrete Fourier transform [DFT] is a powerful computation tool which allow us
to evaluate the Fourier transform X(ejω) on a digital computer (or) specially designed
hardware .unlike DTFT, which is defined for finite of infinite sequences ,DFT is defined only
for sequence of finite of infinite length. since X(e jω) is continues and periodic , DFT is
obtained by sampling one period of the Fourier transform at a finite no of frequency points
.DFT plays an important role in the implementation of many signal processing algorithms.
Apart from determining the frequency content of a signal .DFT performs linear filtering in
frequency domain. Discrete Fourier transform [DFT] is given by, X(k)=∑x(n) e -j2πkn/N where
n and k varies 0,1,2…N-1.the inverse DFT is given by
x(n) = (1/N) ∑X (k) ej2πkn/N where n and k varies 0,1,2…N-1.
ALGORITHM:
1. DIRECT COMPUTATION METHOD:
Read the input sequence and compute its length.
Compute the imaginary and real part of the sequence.
Plot the magnitude and phase response of the DFT sequence.
2. FFT ALGORITHM:
Represent the given discrete sequence in the vector form.
Define the length of required DFT.
Incorporate the condition N = L.
If the condition is true compute DFT by using suitable MATLAB command.
If N < L , display the error message.
IfN > L, pad extra zeros to the original discrete sequence asrequired and then
computethe DFT using suitable MATLAB command.
Display the magnitude and phase values of the DFT sequence.
Plot a stem graph between indices of N and absolute values.
Plot a stem graph between indices of N and angle values.
3. IDFT ALGORITHM:
Represent the given discrete sequence in the vector form.
Define the length of required IDFT.
Incorporate the condition N = L.
311119106057 VANITHA LAKSHMI M
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
If the condition is true compute IDFT by using suitable MATLABcommand.
If N < L , display the error megasege.
IfN > L, pad extra zeros to the original discrete sequence as required and
Thencompute the IDFT using suitable MATLABcommand.
Display the magnitude and phase values of the IDFT sequence.
Plot a stem graph between indices of N and absolute values.
Plot a stem graph between indices of N and angle values.
PROGRAM:
1.DFT
clc
clear all
close all
x=input('enter the value')
N=length(x)
n=0:1:N-1;
k=0:1:N-1;
wn=exp(-j*2*pi/N);
b=n'.*k;
c=wn.^b;
y=x*c
subplot(2,1,1)
stem(n,x)
xlabel('time');
ylabel('amplitude');
title('input value');
y1=abs(y)
subplot(2,1,2)
stem(y1)
xlabel('time');
ylabel('amplitude');
title('DFT');
INPUT:
enter the value> [1 3 5 2]
311119106057 VANITHA LAKSHMI M
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
OUTPUT:
x =
1 3 5 2
N = 4
y =
Columns 1 through 3:
11.0000 + 0i -4.0000 - 1.0000i 1.0000 + 0.0000i
Column 4:
-4.0000 + 1.0000i
y1 =
11.0000 4.1231 1.0000 4.1231
GRAPH:
Figure 4.1 Discrete Fourier Transform
311119106057 VANITHA LAKSHMI M
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
Figure 4.1 Discrete Fourier Transform
CALCULATIONS:
311119106057 VANITHA LAKSHMI M
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
2. FFT
clc
clear all
close all
x=input('enter the sequence')
L=length(x)
N=input('enter the length')
if N==L
y=fft(x)
elseif N<L
disp('input error')
else
N>L
x1=[x,zeros(1,(N-L))]
y=fft(x1)
end
subplot(2,1,1);
stem(x)
xlabel('time');
ylabel('amplitude');
title('input value');
grid on;
y1=abs(y)
subplot(2,1,2);
stem(y1)
xlabel('time');
ylabel('amplitude');
title('FFT');
grid on;
INPUT:
enter the sequence> [1 2 3 4]
OUTPUT:
x =
1 2 3 4
L = 4
enter the length>4
N = 4
y =
10 + 0i -2 + 2i -2 + 0i -2 - 2i
y1 =
10.0000 2.8284 2.0000 2.8284
311119106057 VANITHA LAKSHMI M
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
GRAPH:
Figure 4.2 Discrete Fourier Transform Using FFT Algorithm
311119106057 VANITHA LAKSHMI M
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
CALCULATIONS:
311119106057 VANITHA LAKSHMI M
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
3. IDFT
clc
clear all
close all
x=input('enter the value')
L=length(x)
N=input('enter the length')
if N==L
y=ifft(x)
elseif N<L
disp('input error')
else
N>L
x1=[x,zeros(1,(N-L))]
y=ifft(x1)
end
y1=abs(y)
stem(y1)
subplot(2,1,1);
stem(x)
xlabel('time');
311119106057 VANITHA LAKSHMI M
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
ylabel('amplitude');
title('input value');
grid on;
y1=abs(y)
subplot(2,1,2);
stem(y1)
xlabel('time');
ylabel('amplitude');
title('IDFT');
grid on;
INPUT:
enter the value> [8 8 8 8 8 8 8 0]
OUTPUT:
x =
8 8 8 8 8 8 8 0
L = 8
enter the length> 8
N = 8
y =
Columns 1 through 4:
7.0000 + 0i -0.7071 + 0.7071i 0 + 1.0000i 0.7071 + 0.7071i
Columns 5 through 8:
1.0000 + 0i 0.7071 - 0.7071i 0 - 1.0000i -0.7071 - 0.7071i
y1 =
7 1 1 1 1 1 1 1
y1 =
7 1 1 1 1 1 1 1
311119106057 VANITHA LAKSHMI M
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
GRAPH:
Figure 4.3 Inverse Discrete Fourier Transform
311119106057 VANITHA LAKSHMI M
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)
CALCULATION:
RESULT:
Thus the DFT and IDFT of the given discrete sequence and the magnitude and phase
response was plotted.
311119106057 VANITHA LAKSHMI M