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

DSPLab Assignment 06

The document is an assignment for a Digital Signal Processing course focused on the Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT) of sequences. It includes theoretical background, MATLAB code implementations for both 4-point and 8-point DFT and IDFT, and outputs of the computations. Additionally, it concludes with a list of new functions learned during the assignment.

Uploaded by

Apurva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

DSPLab Assignment 06

The document is an assignment for a Digital Signal Processing course focused on the Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT) of sequences. It includes theoretical background, MATLAB code implementations for both 4-point and 8-point DFT and IDFT, and outputs of the computations. Additionally, it concludes with a list of new functions learned during the assignment.

Uploaded by

Apurva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Digital Signal

Processing
(EET 3051)

ASSIGNMENT SET – 06

Discrete Fourier Transform (DFT) and Inverse Discrete Fourier


Transform (IDFT) of a sequence

Submission Date:

Branch: ECE
Section:
Name Registration No. Signature
Tirthapada Sahoo 2241019160

Department of Electronics & Communication


Engineering
Institute of Technical Education and Research
(Faculty of Engineering)
Siksha ‘O’ Anusandhan (Deemed to be
University)
Bhubaneswar

2 | Page
1. AIM: To develop program for DFT and IDFT of a sequence.

Theory:

The Discrete Fourier Transform (DFT) of a sequence is given by


N −1 − j 2 π nk
DFT{x(n)} = X ( k )= ∑ x (n)e N
, for k=0, 1, 2….. N-1
n=0

The Inverse Discrete Fourier Transform (IDFT) of a sequence given by


N−1 j 2 π nk
1
IDFT{X(k)} = x ( n )= ∑ X (k )e N , for n = 0, 1, 2….. N-1
N k=0

3. Implementation: Write MATLAB code.


1. Find the 4point and 8 point DFT of a sequence given by x(n)= {1,1,1,1}.
%CODE
clc; clear all; close all;
x = [1 1 1 1]; % Input sequence
% 4-point DFT
N1 = 4;
n1 = 0:N1-1;
k1 = n1';
W1 = exp(-1j*2*pi*k1*n1/N1);
X4 = W1* x.';
X_4 = fft(x, 4);
disp('4-point DFT using DFT formula:');
disp(X4);
disp('4-point DFT using fft() function:');
disp(X_4)
figure(1);
subplot(3,1,1)
stem(n1,x)
xlabel('Time')
ylabel('Amplitude')
title('Given Sequence')
subplot(3,1,2)
stem(n1,X4)
xlabel('Time')
ylabel('Amplitude')
title('4-point DFT using DFT formula')
subplot(3,1,3)
stem(n1,X_4)
xlabel('Time')
ylabel('Amplitude')
title('4-point DFT using fft() function')
gtext('Tirtha 2241019160')
% 8-point DFT (zero-padding to length 8)

3 | Page
N2 = 8;
x8 = [x, zeros(1, N2 - length(x))]; % Zero-pad to 8 samples
n2 = 0:N2-1;
k2 = n2';
W2 = exp(-1j*2*pi*k2*n2/N2);
X8 = W2 * x8.';
X_8 = fft(x, 8);
disp('8-point DFT using DFT formula:');
disp(X8);
disp('8-point DFT using fft() function:');
disp(X_8)
figure(2);
subplot(3,1,1)
stem(n2,x8)
xlabel('Time')
ylabel('Amplitude')
title('Given Sequence')
subplot(3,1,2)
stem(n2,X8)
xlabel('Time')
ylabel('Amplitude')
title('8-point DFT using DFT formula')
subplot(3,1,3)
stem(n2,X_8)
xlabel('Time')
ylabel('Amplitude')
title('8-point DFT using fft() function')
gtext('Tirtha 2241019160')

%OUTPUT
4-point DFT using DFT formula:
4.0000 + 0.0000i
-0.0000 - 0.0000i
0.0000 - 0.0000i
0.0000 - 0.0000i
4-point DFT using fft() function:
4 0 0 0
8-point DFT using DFT formula:
4.0000 + 0.0000i
1.0000 - 2.4142i
-0.0000 - 0.0000i
1.0000 - 0.4142i
0.0000 - 0.0000i
1.0000 + 0.4142i
0.0000 - 0.0000i
1.0000 + 2.4142i
8-point DFT using fft() function:
Columns 1 through 5
4.0000 + 0.0000i 1.0000 - 2.4142i 0.0000 + 0.0000i 1.0000 -
0.4142i 0.0000 + 0.0000i
Columns 6 through 8
1.0000 + 0.4142i 0.0000 + 0.0000i 1.0000 + 2.4142i
>>

4 | Page
%PLOT

% 4-point DFT

Given Sequence
Amplitude

1
0.5
0
0 0.5 1 1.5 2 2.5 3
Time
4-point DFT using DFT formula
Amplitude

4
2
0
0 0.5 1 1.5 2 2.5 3
Time
4-point DFT using fft() function
Amplitude

4
2
0
0 0.5 1 1.5 2 2.5 3
Tirtha 2241019160 Time

% 8-point DFT

Given Sequence
Amplitude

1
0.5
0
0 1 2 3 4 5 6 7
Time
8-point DFT using DFT formula
Amplitude

4
2
0
0 1 2 3 4 5 6 7
Time
8-point DFT using fft() function
Amplitude

4
2
0
0 1 2 3 4 5 6 7
Tirtha 2241019160 Time

5 | Page
2. Find the 4point and 8 point IDFT of a sequence given by X(k) = {1,0,
1 ,0}.
%CODE
clc; clear all; close all
% Frequency domain input sequence
X = [1 0 1 0];
% 4-point IDFT
N1 = 4;
k1 = 0:N1-1;
n1 = k1';
W1 = exp(1j*2*pi*n1*k1/N1);% IDFT matrix
x4 = (1/N1) * W1 * X.';% Compute IDFT
disp('4-point IDFT using formula:');
disp(x4);
x_4 = ifft(X);% MATLAB automatically treats length as 4
disp('4-point IDFT using ifft:');
disp(x_4);
% Plot real part of result
figure(1);
subplot(3,1,1)
stem(X)
title('Given Sequence')
xlabel('time n'); ylabel('Amplitude x(n)');
grid on;
subplot(3,1,2)
stem(0:N1-1, real(x4), 'filled');
title('Real Part of 4-point IDFT using formula');
xlabel('time n'); ylabel('Amplitude x(n)');
grid on;
subplot(3,1,3)
stem(0:N1-1, real(x_4), 'filled');
title('Real Part of 4-point IDFT using ifft()');
xlabel('time n'); ylabel('Amplitude x(n)');
grid on;
gtext('Tirtha 2241019160')
% 8-point IDFT (zero-padding X(k) to length 8)
N2 = 8;
X8 = [X, zeros(1, N2 - length(X))];% Zero-pad in frequency domain
k2 = 0:N2-1;
n2 = k2';
W2 = exp(1j*2*pi*n2*k2/N2);% IDFT matrix
x8 = (1/N2) * W2 * X8.';% Compute IDFT
disp('8-point IDFT using formula:');
disp(x8);
x_8 = ifft(X8);% MATLAB computes 8-point IDFT
disp('8-point IDFT using ifft:');
disp(x_8);
% Plot real part of result
figure(2);
subplot(3,1,1)
stem(X8)

6 | Page
title('Given Sequence')
xlabel('time n'); ylabel('Amplitude x(n)');
grid on;
subplot(3,1,2)
stem(0:N2-1, real(x8), 'filled');
title('Real Part of 8-point IDFT');
xlabel('time n'); ylabel('Amplitude x(n)');
grid on;
subplot(3,1,3)
stem(0:N2-1, real(x_8), 'filled');
title('Real Part of 8-point IDFT using ifft()');
xlabel('time n'); ylabel('Amplitude x(n)');
grid on;
gtext('Tirtha 2241019160')

%OUTPUT
4-point IDFT using formula:
0.5000 + 0.0000i
0.0000 + 0.0000i
0.5000 - 0.0000i
0.0000 + 0.0000i
4-point IDFT using ifft:
0.5000 0 0.5000 0
8-point IDFT using formula:
0.2500 + 0.0000i
0.1250 + 0.1250i
0.0000 + 0.0000i
0.1250 - 0.1250i
0.2500 - 0.0000i
0.1250 + 0.1250i
0.0000 + 0.0000i
0.1250 - 0.1250i
8-point IDFT using ifft:
Columns 1 through 5
0.2500 + 0.0000i 0.1250 + 0.1250i 0.0000 + 0.0000i
0.1250 - 0.1250i 0.2500 + 0.0000i
Columns 6 through 8
0.1250 + 0.1250i 0.0000 + 0.0000i 0.1250 - 0.1250i
>>

7 | Page
%PLOT

% 4-point DFT
Amplitude x(n) Amplitude x(n) Amplitude x(n)

Given Sequence
1
0.5
0
1 1.5 2 2.5 3 3.5 4
time n
Real Part of 4-point IDFT using formula
0.5

0
0 0.5 1 1.5 2 2.5 3
time n
Real Part of 4-point IDFT using ifft()
0.5

0
0 0.5 1 1.5 2 2.5 3
Tirtha 2241019160 time n

% 8-point DFT
Amplitude x(n) Amplitude x(n) Amplitude x(n)

Given Sequence
1
0.5
0
1 2 3 4 5 6 7 8
time n
Real Part of 8-point IDFT
0.4
0.2
0
0 1 2 3 4 5 6 7
time n
Real Part of 8-point IDFT using ifft()
0.4
0.2
0
0 1 2 3 4 5 6 7
Tirtha 2241019160 time n

8 | Page
4.Conclusion
Make a list of all the new in-built functions that you learned in this
assignment set.
Sl. No. Function Name Short Description
1 fft() Y = fft(x) returns the discrete Fourier transform (DFT) of
vector x, computed with a fast Fourier transform (FFT)
algorithm.
2 ifft() y = ifft(X) returns the inverse discrete Fourier transform
(DFT) of vector X, computed with a fast Fourier transform
(FFT) algorithm. If X is a matrix,ifft returns the inverse
DFT of each column of the matrix.
3 stem() stem(Y) plots the data sequence, Y, as stems that extend
from a baseline along the x-axis. The data values are
indicated by circles terminating each stem.
3 real() X = real(Z) returns the real part of the elements of the
complex array Z.

Describe (in your own words and handwriting) what you have learned in this
assignment set.

9 | Page
___________________________
(Signature of the Student)
Date:_____/____/_____

10 | P a g e

You might also like