0% found this document useful (0 votes)
2 views

Untitled document (8)

The document outlines an experiment for performing Frequency Analysis using Discrete Fourier Transform (DFT) and Inverse DFT (IDFT) with MATLAB. It includes the aim, required apparatus, theoretical background, algorithms for direct computation, FFT, and IDFT, along with example MATLAB programs and outputs. The results demonstrate the computation of DFT and IDFT for given sequences and the corresponding magnitude and phase responses plotted.

Uploaded by

aksheenjane03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Untitled document (8)

The document outlines an experiment for performing Frequency Analysis using Discrete Fourier Transform (DFT) and Inverse DFT (IDFT) with MATLAB. It includes the aim, required apparatus, theoretical background, algorithms for direct computation, FFT, and IDFT, along with example MATLAB programs and outputs. The results demonstrate the computation of DFT and IDFT for given sequences and the corresponding magnitude and phase responses plotted.

Uploaded by

aksheenjane03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LOYOLA - ICAM

COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

Ex.No -4
Frequency Analysis using Discrete Fourier Transform
Date:

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(ejω) 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.
●​ If the condition is true compute IDFT by using suitable MATLABcommand.
●​ If N < L , display the error megasege.
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

●​ 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.FFT:
a = input('Enter The sequence: ');
n = input('Enter the number of points for FFT: ');
n1 = length(a);
if n == n1
X = fft(a, n);
elseif n1 < n
a = [a, zeros(1, n - n1)];
X = fft(a, n);
else
disp('Error in input');
end
disp(X);
magnitudeX = abs(X);
subplot(2,1,1);
stem(0:n-1,a);
title('Input');
xlabel('Index');
ylabel('Magnitude');
subplot(2,1,2);
stem(0:n-1, magnitudeX);
title('FFT');
xlabel('Index');
ylabel('Magnitude');

OUTPUT:
Enter The sequence: [1 1 2 2 3 3 4 4]
Enter the number of points for FFT: 8
Columns 1 through 5

20.0000 + 0.0000i -2.0000 + 4.8284i -2.0000 + 2.0000i -2.0000 + 0.8284i


0.0000 + 0.0000i

Columns 6 through 8

-2.0000 - 0.8284i -2.0000 - 2.0000i -2.0000 - 4.8284i


GRAPH:

2. IFFT:

a = input('Enter The sequence: ');


n = input('Enter the number of points for FFT: ');
n1 = length(a);
if n == n1
X = ifft(a, n);
elseif n1 < n
a = [a, zeros(1, n - n1)];
X =ifft(a, n);
else
disp('Error in input');
end
disp(X);
magnitudeX = abs(X);
subplot(2,1,1);
stem(0:n-1,a);
title('Input');
xlabel('Index');
ylabel('Magnitude');
subplot(2,1,2);
stem(0:n-1, magnitudeX);
title('FFT');
xlabel('Index');
ylabel('Magnitude');

OUTPUT:

Enter The sequence: [20.0000 + 0.0000i -2.0000 + 4.8284i -2.0000 + 2.0000i -2.0000 +
0.8284i 0.0000 + 0.0000i -2.0000 - 0.8284i -2.0000 - 2.0000i -2.0000 - 4.8284i]

Enter the number of points for FFT: 8


1.0000 1.0000 2.0000 2.0000 3.0000 3.0000 4.0000 4.0000
GRAPH:

​ ​ ​ ​
3. FFT USING FORMULA

x = input('Enter the sequence: ');


N = length(x);
n = 0:N-1;
k = n';
WN = exp(-1i * pi * 2 / N * (k * n));
y = WN * x';
C1 = abs(y);
subplot(2,1,1);
stem(n, x, 'filled');
xlabel('Sample Index');
ylabel('Amplitude');
title('Input Sequence');
grid on;
subplot(2,1,2);
stem(n, C1, 'filled');
xlabel('Frequency Index');
ylabel('Magnitude');
title('Magnitude Spectrum of FFT');
grid on;
disp('FFT result:');
disp(y);

OUTPUT:
Enter the sequence: [1 1 2 2 3 3 4 4]
FFT result:
20.0000 + 0.0000i
-2.0000 + 4.8284i
-2.0000 + 2.0000i
-2.0000 + 0.8284i
0.0000 - 0.0000i
-2.0000 - 0.8284i
-2.0000 - 2.0000i
-2.0000 - 4.8284i
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

GRAPH:

4.IFFT USING FORMULA:

x = input('Enter the sequence: ');


N = length(x);
n = 0:N-1;
k = n';
WN_inv = exp(1i * pi * 2 / N * (k * n));
y = (1/N) * (WN_inv * x');
C1 = abs(y);
subplot(2,1,1);
stem(n, x, 'filled');
xlabel('Sample Index');
ylabel('Amplitude');
title('Input Sequence');
subplot(2,1,2);
stem(n, C1, 'filled');
xlabel('Time Index');
ylabel('Magnitude');
title('Magnitude Spectrum of IFFT');
disp('IFFT result:');
disp(y);

OUTPUT:
Enter the sequence: [1 1 1 1 1 1 1 1]
IFFT result:
1.0000 + 0.0000i
-0.0000 - 0.0000i
-0.0000 + 0.0000i
-0.0000 - 0.0000i
0.0000 + 0.0000i
-0.0000 + 0.0000i
-0.0000 + 0.0000i
0.0000 - 0.0000i
LOYOLA - ICAM
COLLEGE OF ENGINEERING AND TECHNOLOGY (LICET)

GPRAH:

Preparation 5
Conduction &
Observation 5
Result Execution
Viva-Voce &
5
Inference
Record 5
Total 20

RESULT:
Thus the DFT and IDFT of the given discrete sequence and the magnitude and phase
response was plotted.

You might also like