FLOWCHART:
START
ENTER THE DISCRETE
TIMEINPUT SEQUENCE
PERFORM THE DFT USING IN-BUILT FFT AND
USING DIRECT FORMULA ON THE GIVEN
INPUT SEQUENCE
PLOT THE MAGNITUDE AND PHASE
RESPONSE
STOP
10
EX. NO : 3
DATE :
CALCULATION OF DFT OF A SIGNAL
AIM:
To write a MATLAB program to perform the Discrete Fourier Transform for the given two
sequences and to plot their magnitude and phase response.
APPARATUS REQUIRED:
Computer with MATLAB software
THEORY:
DISCRETE FOURIER TRANSFORM
Fourier analysis is extremely useful for data analysis, as it breaks down a signal into
constituent sinusoids of different frequencies. For sampled vector data Fourier analysis is
performed using the Discrete Fourier Transform (DFT).
It finds its application in Digital Signal processing including Linear filtering, Correlation
analysis and Spectrum analysis.
Consider a complex series x[n] with N samples of the form x0, x1, x2, x3… xk ... xN-1, Where x
is a complex number xi = xreal + jximag. Further, assume that the series outside the range 0, N-1
is extended N-periodic, that is, xk = xk+N for all k. The FT of this series is denoted as X (k)
and has N samples. The forward transform is defined as
N 1
j2 n k N
X(k) x ( n) e , for k 0...N 1
n0
The inverse transform is defined as
N 1
1 j 2 n k N
x(n)
N
X (k ) e , for n 0...N 1
k 0
Although the functions here are described as complex series, setting the imaginary part to 0
can represent real valued series. In general, the transform into the frequency domain will be a
complex valued function, that is, with magnitude and phase.
Magnitude X (k ) ( X real * X real X imag * X imag ) 0.5
X imag
Phase tan 1
X real
11
LIBRARY FUNCTIONS:
exp: Exponential Function.
exp (X) is the exponential of the elements of X, e to the power X. For complex
Z=X+i*Y, exp (Z) = exp(X)*(COS(Y) +i*SIN(Y)).
disp: Display array.
disp (X) is called for the object X when the semicolon is not used to terminate a
statement.
max: Maximum elements of an array
C = max (A, B) returns an array of the same size as A and B with the largest elements
taken from A or B.
fft: Fast Fourier transform.
fft(x) is the discrete Fourier transform (DFT) of vector x. For the matrices, the FFT
operation is applied to each column. For N-Dimensional arrays, the FFT operation
operates on the first non-singleton dimension.
RESULT:
The program for Discrete Fourier Transform was performed with library functions and
without library functions using MATLAB. The results were verified by manual calculation.
12
SAMPLE VIVA QUESTIONS:
1. Define DFT of a sequence x[n].
2. What are the ‘Twiddle factors’ of FFT?
3. Calculate the DFT of x[n]=δ[n-n0], 0≤n0≤N-1.
4. State the Linearity property and Circular shift property of Discrete Fourier transforms.
5. Prove the Linearity property of DFT.
6. Prove the Circular shift property of DFT.
7. List out the properties of DFT.
8. X[n] is obtained from the inverse DFT of an N-point sequence X(K), where K=0,1,
2,….N-1 is defined as _______________.
9. What is meant by Zero padding? What are its uses?
10. State the relationship between DTFT and Z-transform.
11. State the relationship between Z transform and DFT.
12. State the relationship between DTFT and DFT.
13. The direct computation of the discrete Fourier transform of a sequence x[n] requires
__________ real multiplications and _________ real additions.
14. The direct computation of the Discrete Fourier transform of a sequence x[n] requires
______ complex multiplications and ______ complex additions.
SAMPLE ASSIGNMENT QUESTIONS:
1. Compute DFT of the sequence (sine wave) with N = 8, 16, 32, 50 sample points and
compare the results.
2. Find the spectrum of sum of two sin signals with frequencies f1=100Hz & f2=200Hz.
3. Implement the DFT in MATLAB by matrix method.
4. Perform inverse FFT by using forward FFT for the given complex number.
5. Explore in MATLAB about the following library functions FFT2 & FFTSHIFT.
6. Write a program in MATLAB to find the DFT of a given two sequence in direct
method and FFT method. Plot the error signal
a.x1 [n] = [1 1 11] b. x2[n] = [1 2 3 4]
7. Write a program in MATLAB to Prove that time domain convolution is equal to
frequency domain Multiplication.
a. x1 [n] = [1 1 2 2 ] b. x2[n] = [1 2 3 4 ].
13
Experiment 3 Date: 10/02/2025
Register number: URK23EC1015
Calculation of DFT of a Signal
MATLAB Code:
clc;
clear;
x = input('Enter the sequence (x): ');
N=length(x);
X=zeros(1,N);
subplot(3,3,1);
stem(x);
title('x(n)');
xlabel('n');
ylabel('x[n]');
disp(x);
for k = 0 : N-1
for n = 0 : N-1
X(k+1)=X(k+1)+x(n+1)*exp(-1j*2*pi*k*n/N);
end
end
subplot(3,3,2);
stem(X);
title('X(k)');
xlabel('n');
ylabel('X[k]');
disp(X);
a = fft(x,N);
subplot(3,3,3);
stem(a);
title('FFT');
xlabel('x');
ylabel('N');
disp(a);
Y = abs(a);
subplot(3,3,4);
stem(Y);
title('ABSOLUTE VALUE');
xlabel('x');
ylabel('N');
disp(a);
Output: