Lab 8
Lab 8
Faculty of Engineering
Experiment # 8
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:
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
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')
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
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) = [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 :DFT
Figure :DFT
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