0% found this document useful (0 votes)
75 views17 pages

Lab 8

The document describes an experiment on the properties of the discrete Fourier transform (DFT) and inverse DFT. It discusses linearity, circular folding, and circular shift properties of the DFT. It provides MATLAB code examples to demonstrate these properties. The document also includes a section on the inverse DFT function and provides a MATLAB example to evaluate the DFT and inverse DFT of a sample signal. Finally, it presents an assignment asking to perform a 2D Fourier transform on two images, exchange their phase spectra, and reconstruct the images using the inverse transform.

Uploaded by

Engr Umer Cheema
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)
75 views17 pages

Lab 8

The document describes an experiment on the properties of the discrete Fourier transform (DFT) and inverse DFT. It discusses linearity, circular folding, and circular shift properties of the DFT. It provides MATLAB code examples to demonstrate these properties. The document also includes a section on the inverse DFT function and provides a MATLAB example to evaluate the DFT and inverse DFT of a sample signal. Finally, it presents an assignment asking to perform a 2D Fourier transform on two images, exchange their phase spectra, and reconstruct the images using the inverse transform.

Uploaded by

Engr Umer Cheema
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/ 17

Registration#2014-EE-453

University of Engineering & Technology Lahore

Faculty of Engineering

Experiment # 8

Title: Properties of Discrete Fourier Transform and Inverse DFT

Equipment Required: Personal computer (PC) with windows operating system and
MATLAB software
Theory:
In Lab Experiment 7, we have discussed in detail the Discrete Fourier Transform (DFT) for the
analysis of signals. It is a sampled version of the DTFT, hence it is better suited to numerical
evaluation on computers.

Where X(k) is an N-point DFT of x[n]. Note that X(k) is a function of a discrete integer k, where
k ranges from 0 to N-1.
Properties:

Linearity: The DFT is a linear transform

If x1(n) and x2(n) have N1-points and N2 -points


respectively, then N3= max(N1, N2)

Circular Folding: If an N point sequence is folded, then the result x(-n) would not be an N
point sequence, and it would not be possible to compute its DFT. Therefore, we use modulo-N
operation on the argument(-n) and define the folding by

This a called a circular folding. To visualize it,


imagine that the sequence x(n) is wrapped around a circle in the counterclockwise direction that
n= 0 and n=N overlap. Then x((-n))N can be viewed as a clockwise wrapping of x(n) around the
circle. That’s why it is called circular folding.
In MATLAB the circular folding can be achieved by x = x(mod(−n, N) + 1.
Example: Let x(n) = 10(0.8)n 0 ≤ n ≤ 10
a. Determine and plot x((-n))11
b. Verify the circular folding property
MATLAB Script
a.

n=0:100; x= 10*(0.8).^n;
y=x(mod(-n,11)+1);
subplot(2,1,1);
stem(n,x); title('original sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,1,2); stem(n,y); title('circularly folded sequence')
xlabel('n'); ylabel('x(-n) mod 10')

Figure : Circular Folding

b.
n=0:10;
x= 10*(0.8).^n; X= fft(x,11);
Y=fft(x(mod(-n,11)+1), 11);
subplot(2,2,1); stem(n, real(X));
title('Real {DFT of x(n)}'); xlabel('k')
subplot(2,2,2); stem(n, imag(X));
title('Imag {DFT of x(n)}'); xlabel('k')
subplot(2,2,3); stem(n, real(Y));
title('Real {DFT of x(-n)11}'); xlabel('k')
subplot(2,2,4); stem(n, imag(Y));
title('Imag {DFT of x(-n)11}'); xlabel('k')

Simulation

Figure : Circular Folding

Circular Shift property: If an N-point sequence is shifted in either direction, then the result is
no longer between 0 ≤n ≤ N-1. Therefore, we first convert x(n) into its periodic extension, and
then shift it by m samples to obtain

This is called periodic shift. then this periodic shift is converted into N point sequence. Resulting
sequence is

Example: Let x(n) = 10(0.8)n 0 ≤ n ≤ 10. Determine and plot x((n-6))15


MATLAB Script
function y = cirshftt(x,m,N)
% Circular shift of m samples u r t size N in sequence X: (time domain)
%...................................................................
%[y] = cirshft(x, m, N)
% y = output sequence containing the circular shift
%X = input sequence of length <= N
% m = sample shift
% N = size of circular buffer
% Method: y(n) = x((n-m) mod N
% Check for length of x
if length(x) > N
error('N must be >= the length of X ' )
end
X = [x zeros(1, N-length(x))];
n = [0:1:N-1];
n = mod(n-m,N) ;
y = X(n+1);
n=0:10;
x=10*(0.8).^n;
y= cirshftt(x, 6,15);
n= 0:14;
x= [x, zeros(1,4)];
subplot(2,1,1); stem(n,x);title('original sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,1,2); stem(n,y); title('circularly shift sequence, N=15')
xlabel('n'); ylabel('x(n-6) mod 15');
Simulation:

Figure : Circular Shift property

Inverse DFT Function

function [xn] =idft (Xk, N)


%Compute Inverse Discrete Transform
n= [0:1:N-1];
k = [0:1:N-1];
WN = exp (-j * 2 * pi / N);
nk = n' * k;
WNnk = WN .^ (-nk) ;
xn = (Xk * WNnk)/N;

Example: Let x(n) = [1 2 3 4 5]. Evaluate and plot magnitude DFT and IDFT.
MATLAB Script
x=[1,2,3,4,5];
N= 5;
k= [0:1:N-1];
X=fft(x);
Y=ifft(X);
magY= abs(Y);
magX = abs(X); angX = angle(X);
realX = real(X); imagX = imag(X);
subplot(2,1,1);
stem(k,magX);grid
xlabel('k'); title('Magnitude');
subplot(2,1,2);
stem(k,magY);grid
xlabel('k'); title('Magnitude');
Simulation

Figure :inverse DFT


Tasks:
1. The first five values of the 8-point DFT of a real-valued sequence X (n) are given by
{0.25, 0.125 − j0.3, 0, 0.125 − j0.06, 0.5}
Determine the DFT of
a. x(n) = x((n + 5))10
n=0:10;x=[0.25,0.125-0.3i,0,0.125-0.06i,0.5,0,0,0,0,0,0];
y=x(mod(n+5,10)+1);
z=fft(y);
subplot(2,1,1);
stem(n,abs(x)); title('original sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,1,2); stem(n,abs(z)); title('circularly folded sequence')
xlabel('n'); ylabel('x(-n) mod 10')

Figure :DFT

b. y(n) = cirsularconvolve x(n) and x((−n))8 with n = 8,


n=0:10;x=[0.25,0.125-0.3i,0,0.125-0.06i,0.5,0,0,0,0,0,0];
y=x(mod(-n,8)+1);
z=cconv(x,y);
subplot(2,1,1);
m=[0:length(x)+length(y)-2];
stem(n,abs(x)); title('original sequence')
xlabel('n'); ylabel('x(n)');
subplot(2,1,2); stem(m,abs(z)); title('circularly conuolve sequence')
xlabel('n'); ylabel('cconv(x(n),x(-n)10)')

Figure :DFT

2. Determine the DFT and IDFT of following signals.


a. x(n) = {1, j, j, 1} N = 4
n=0:10; x=[1,i,i,1,0,0,0,0,0,0,0];
N= length(x);
k= [0:1:N-1];
X=fft(x);
Y=ifft(X);
subplot(3,1,1);
stem(k,abs(x));grid
xlabel('k'); title('abs(x(n))');
subplot(3,1,2);
stem(k,abs(X));grid
xlabel('k'); title('abs(DFT x(n))');
subplot(3,1,3);
stem(k,abs(Y));grid
xlabel('k'); title('abs(IDFT X(n))');

Figure DFT &IDFT

b. x(n) = {Sin(0.5πn)} 0 ≤ n ≤ 100


n=0:100;
x=[sin(0.5*pi*n)];
N= length(x);
k= [0:1:N-1];
X=fft(x);
Y=ifft(X);
subplot(3,1,1);
stem(k,x);grid
xlabel('k'); title('x(n)');
subplot(3,1,2);
stem(k,X);grid
xlabel('k'); title('DFT x(n)');
subplot(3,1,3);
stem(k,Y);grid
xlabel('k'); title('IDFT X(n)');

Figure :DFT & IDFT

Assignment:
Write a MATLAB code to evaluate the two-dimensional Fourier transform of the
two images from MATLAB. Plot the corresponding frequency representations and reconstruct
the two images by inverse transformation, but exchanging their phase spectra.

MATLAB CODE:
j=imread('piout.jpg');
I=imread('gggggg.jpg');
pandaimage = imresize(I,[680 425]); jafarimage = imresize(j,[680 425]); %
resizing of image
figure(1);imshow(pandaimage); title('Original panda image');figure(2)
imshow(jafarimage);title('Original jafar image');
two_d_pic=rgb2gray(pandaimage);figure(4); imshow(two_d_pic);title('2D picture
of panda ') % conversion of 3D picture to 2D
two_d_pic1=rgb2gray(jafarimage);figure(5);imshow(two_d_pic1);title('2D
picture of jafar ')
transform=fft2(double(two_d_pic)); % fft analysis of 2D picture
transform1=fft2(double(two_d_pic1));
shift_transform=fftshift(transform);figure(7);imshow(shift_transform);title('
shifted transform of panda')
shift_transform1=fftshift(transform1);figure(8);imshow(shift_transform1);titl
e('shifted transform of jafar')
panda_magnitude=abs(shift_transform);
jafar_magnitude=abs(shift_transform1);
pandya_angle = angle(transform)
jafar_angle = angle(transform1);
figure(9);imshow(pandya_angle,[-pi pi]);title('angle of panda')
figure(10);imshow(jafar_angle,[-pi pi]);title('angle of jafar')
figure(11);imshow(panda_magnitude, [24 1000000]);title('magnitude of panda')
figure(12);imshow(jafar_magnitude, [24 1000000]);title('magnitude of jafar
pic')
spectrum_exchange = abs(transform).*exp(1j*jafar_angle);
spectrum_exchange1 = abs(transform1).*exp(1j*pandya_angle);
IFFT = ifft2(spectrum_exchange);% Applying Inverse 2D FFT
IFFT1 = ifft2(spectrum_exchange1);
cmin = min(min(abs(IFFT ))); % Limits for Plotting
cmax = max(max(abs(IFFT )));
dmin = min(min(abs(IFFT1)));
dmax = max(max(abs(IFFT1)));
figure(13); imshow(abs(IFFT),[cmin cmax]);title('Reconstruction of Exchange
spectra of FFFT')
figure(14); imshow(abs(IFFT1),[dmin dmax]);title('Reconstruction of Exchange
spectra of FFFT1')

OUTPUT

You might also like