DSP Lab
DSP Lab
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:
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.
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:
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:
CALCULATIONS:
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
GRAPH:
CALCULATIONS:
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');
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
GRAPH:
CALCULATION:
RESULT:
Thus the DFT and IDFT of the given discrete sequence and the magnitude and phase
response was plotted.