DSPB301 NOTES - 7 The 2D DFT - 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

The 2D – Discrete Fourier Transform (DFT) and 2D – Inverse Discrete Fourier Transform (IDFT)

j 2

WN  e N
is the defining relation for the DFT and IDFT and included in the 1D DFT and IDFT formula
as follows:
N 1
X DFT [k ]   x[n]WNnk , k  0, 1, ..., N  1
n 0

1 N 1
x[n]  
N k 0
X DFT [k ].WNnk , n  0, 1, ..., N  1

The first set of N DFT equations in N unknowns may be expressed in matrix form as X  WNX

Where X and x and (Nx1) matrices , and WNX is a (NxN) square matrix called the DFT matrix (kernel).

 X [0]  WN0 WN0 WN0 ..W 0   x[0] 


 X [1]   0 1 N 1  
   WN WN WN2 ...WN . x[1] 
 X [2]  WN0 WN2 WN4 ...WN2( N 1)   x[2] 
   0  
 X [ N  1] WN WN ...WN( N 1)( N 1)   x[ N  1]
N 1
WN2( N 1)

The exponents in the element of WNt of WN are called twiddle factors.



Example 1: Find the 1D DFT using matrices if x[n]  {1, 2, 1, 0} and N=4. Note that
j 2

WN  e 4
  j , the DFT may be obtained by solving the matrix product as follows:

The Kernel is standard for a 4x4 2D DFT

One dimension = kernel x input sequence.

 X [0] WN0 WN0 WN0 W 0  1 1 1 1  1  4 


 X [1]   0 3 1  j  1 j  2  2 j 
   WN WN1 WN2 .WN       

 X [2] WN0 WN2 WN4 .WN6
1  1 1  1  1   0 
   0       
 X [3] WN WN3 WN6 .WN9  1 j  1  j  0  2 j 

Multiplying the matrices (Add Horizontally)

(1x1)  (1x 2) (1x1) (1x0)  1  4 


 (1x1)  ( jx2) (1x1) ( jx0)  2  2 j 
     
 (1x1)  (1x 2) (1x1) (1x0) 1  0 
     
 (1x1)  ( jx2) (1x1) ( jx0) 0  2 j 
The result of the X DFT [k ]  {4,  2 j , 0, 2 j}
Example 2: Find the IDFT of [k] = {4,  2 j, 0, 2 j}
*
1st conjugate the sequence to get X DFT [k ]  {4, 2 j , 0,  2 j}
*
2nd Find the DFT of X DFT [ k ] using the 4x4 kernel matrix

1 1 1 1   4   4
1  j  1 j   2 j  8
*
DFT{ X DFT }    
1  1 1  1   0  4
     
1 j  1  j   2 j  0

Finally, conjugate the above result, if complex and divide by N=4 to get the IDFT of X DFT [k ] .

1
IDFT{ X DFT [k ]}  {4, 8, 4 0}  {1, 2, 1, 0}
4
Example 3:

Calculate the 4-point DFT for the digital sequence x[n]  {0, 1, 2, 3} using the matrix method.

Example 4:

Compute the 2D DFT of the grayscale image which is given by:

1 1 1 1
1 1 1 1
f (m, n)  
1 1 1 1
 
1 1 1 1

F(k,l) = kernel (K) x f(m,n) x kernel (K) (transpose)

F (k , l )  k  f (m, n)  k T

1 1 1 1 
1  j  1 j 
ker nel T    (Interchange rows and columns)
1  1 1  1
 
1 j  1  j 
Solution:

F (u, v)  k  f (m, n)  k T

1 1 1 1  1 1 1 1 1 1 1 1 
1  j  1 j  1 1 1 1 1  j  1 j 
 
F (u, v)    
1  1 1  1 1 1 1 1 1  1 1  1
     
1 j  1  j  1 1 1 1 1 j  1  j 
4 4 4 4 1 1 1 1  16 0 0 0
0 0 0 0 1  j  1 j   0
  0 0 0
  
0 0 0 0 1  1 1  1   0 0 0 0
     
0 0 0 0 1 j  1  j   0 0 0 0

Matlab Code to solve the matrix

%Matrix Multiplication of Image Kernel for solve 2D DFT


clc, clear all, close all
k1=[1 1 1 1; % k1 is the image kernel for a 4x4 DFT
1 -i -1 i;
1 -1 1 -1;
1 i -1 -i];

Img=[1 1 1 1; % Img is a random image


1111
1 1 1 1;
1 1 1 1];
z=k1*Img

k2=k1'%Find the transpose of k1


f1=z*k2 % 2D DFT

%Simple Example of a Frequency Spectrum

clear all, close all, clc


fs=150;
t=0:1/fs:1;
f=5;
x=sin(2*pi*f*t);
x_mag=abs(x);
df=-fs/2:1:fs/2;
figure(1);

plot(t,x);

title(‘sine wave signal’);

figure (2);

plot(df,x_mag);

title(‘spectrum of sine wave’);


%Fourier Spectrum of Image

clear all, close all, clc


f=imread('cameraman.tif');
id=im2double (f);
figure(1), imshow(f);

f2=fft2(id);
figure(2), imshow (f2);

ft_shift=fftshift(f2);
imshow (log(1+abs(ft_shift)),[])

You might also like