FFT 2D
FFT 2D
FFT 2D
Overview
• Signals as functions (1D, 2D)
– Tools
• 1D Fourier Transform
– Summary of definition and properties in the different cases
• CTFT, CTFS, DTFS, DTFT
• DFT
• 2D Fourier Transforms
– Generalities and intuition
– Examples
– A bit of theory
• Discrete Fourier Transform (DFT)
• Discrete Cosine Transform (DCT)
Signals as functions
1. Continuous functions of real independent variables
– 1D: f=f(x)
– 2D: f=f(x,y) x,y
– Real world signals (audio, ECG, images)
2. Real valued functions of discrete variables
– 1D: f=f[k]
– 2D: f=f[i,j]
– Sampled signals
3. Discrete functions of discrete variables
– 1D: y=y[k]
– 2D: y=y[i,j]
– Sampled and quantized signals
– For ease of notations, we will use the same notations for 2 and 3
Images as functions
• Gray scale images: 2D functions
– Domain of the functions: set of (x,y) values for which f(x,y) is defined : 2D lattice
[i,j] defining the pixel locations
– Set of values taken by the function : gray levels
• Digital images can be seen as functions defined over a discrete domain {i,j:
0<i<I, 0<j<J}
– I,J: number of rows (columns) of the matrix corresponding to the image
– f=f[i,j]: gray level in position [i,j]
Example 1: δ function
⎧1 i= j=0
δ [i , j ] = ⎨
⎩0 i , j ≠ 0; i ≠ j
⎧1 i = 0; j = J
δ [i , j − J ] = ⎨
⎩0 otherwise
Example 2: Gaussian
Continuous function
x2 + y2
1
f ( x, y ) = e 2σ 2
σ 2π
Discrete version
i2 + j2
1
f [i , j ] = e 2σ 2
σ 2π
Example 3: Natural image
Example 3: Natural image
Fourier Transform
• Different formulations for the different classes of signals
– Summary table: Fourier transforms with various combinations of
continuous/discrete time and frequency variables.
– Notations:
• CTFT: continuous time FT
• DTFT: Discrete Time FT
• CTFS: CT Fourier Series (summation synthesis)
• DTFS: DT Fourier Series (summation synthesis)
• P: periodical signals
• T: sampling period
• ωs: sampling frequency (ωs=2π/T)
• For DTFT: T=1 → ωs=2π
1D FT: basics
Fourier Transform: Concept
r e jα = r ( cos α + j sin α )
Overview
Transform Time Frequency Analysis/Synthesis Duality
(Continuous Time) C C F (ω ) = ∫ f (t )e − jωt dt Self-dual
Fourier Transform t
(CTFT) 1
2π ω∫
jω t
f (t ) = F (ω ) e dω
f (t ) = ∑ F [k ]e j 2π kt / T
k
Discrete Time Fourier D C Dual with
Transform (DTFT) F (e jω t
) = ∑ f [n]e − j 2πω n / ωs
CTFS
P n
ωs / 2
F ( e jωt ) e j 2πω n / ωs d ω
1
f [ n] =
ωs ∫
− ωs / 2
ω → 2π u
Change of notations: ⎧ω x → 2π u
⎨
⎩ω y → 2π v
Then CTFT becomes
T /2 T /2
1 0 1
∫
− j 2π kt / T
∫ F [k ] =
− jnω0 t
Dn = f T (t ) e dt f (t ) e dt
T0 −T0 / 2 o
T −T / 2
fT0 (t ) = ∑ Dn e jnω0t
2π
n f (t ) = ∑ F [k ]e j 2π kt / T
ω0 = k
T0 T0↔T
fundamental frequency Dn ↔F[k]
CTFS
• Representation of a continuous time signal as a sum of orthogonal
components in a complete orthogonal signal space
– The exponentials are the basis functions
• Fourier series are periodic with period equal to the fundamental in the set
(2π/T0)
• Properties
– even symmetry → only cosinusoidal components
– odd symmetry → only sinusoidal components
CTFS: example 1
CTFS: example 2
From sequences to discrete time signals
• Looking at the sequence as to a set of samples obtained by sampling a real
signal with frequency ωs we can still use the formulas for calculating the
transforms as derived for the sequences by
– Stratching the time axis (and thus squeezing the frequency axis if Ts>1)
normalized frequency
(sample series)
Ω = ωTs frequency (sampled signal)
2π
spectral periodicity in Ω 2π → ωs = spectral periodicity in ω
Ts
– Enclosing the sampling interval Ts in the value of the sequence samples (DFT)
f k = Ts f ( kTs )
DTFT
• Discrete Time Fourier Transform
• Discrete time a-periodic signal
• The transform is periodic and continuous with period Ω0 = 2π
our notations table notations
F ( e jω ) = ∑ f [n]e − j 2πω n / ωs
+∞
F (Ω) = ∑
k =−∞
f [k ]e − jΩk
n
ωs / 2
F ( e jωt ) e j 2πω n / ωs d ω
1
f [k ] =
1
2π ∫π F ( Ω )e
j Ωk
dΩ f [ n] =
ωs −
∫ω /2
2 s
⎛Ω⎞
F ( Ω ) = Fc ⎜ ⎟ non normalized
normalized
Ω = ωTs ⎝ s ⎠
T
frequency frequency
Ts = 2π / ωs Ts = 2π / ωs
Discrete Time Fourier Transform (DTFT)
_
• F(Ω) can be obtained _from Fc(ω) by replacing ω with Ω/Ts. Thus F(Ω) is
identical to Fc(ω) frequency scaled by a factor 1/Ts
– Ts is the sampling interval in time domain
• Notations
⎛Ω⎞
F ( Ω ) = Fc ⎜ ⎟
⎝ Ts ⎠
2π 2π
ωs = → Ts = periodicity of the spectrum
Ts ωs
Ω
ω= → Ω = ωTs normalized frequency (the spectrum is 2π-periodic)
Ts
F (Ω) → F (ωTs ) = F ( 2πω / ωs )
+∞ +∞
F (Ω) = ∑
k =−∞
f [k ]e − j Ωk
→ F (ωTs ) = F (ω ) = ∑
k =−∞
f [k ]e − j 2 kπω / ωs
DTFT: unitary frequency
Ω = 2π u (ω = 2π f )
∞ ∞
F (Ω) = ∑
k =−∞
f [k ]e − j Ωk
→ F (u ) = ∑
k =−∞
f [k ]e − j 2π ku
1
2
1
f [k ] =
2π ∫π
2
F (Ω)e jΩk d Ω → f [ k ] = ∫ F (u )e j 2π ku du =
1
∫ 1
F (u )e j 2π ku du
−
2
∞
⎧
⎪ F (u ) = ∑ f [ k ]e − j 2π ku
NOTE: when Ts=1, Ω=ω and the spectrum is
⎪⎪ k =−∞
2π-periodic. The unitary frequency u=2π/ Ω
⎨
1
2
corresponds to the signal frequency f=2π/ω.
⎪ f [k ] = F (u )e j 2π ku du
∫1
This could give a better intuition of the
⎪ transform properties.
⎪⎩ −
2
Connection DTFT-CTFT
sampling periodizationFc(ω)
f(t)
t 0 _ ω
Fc(ω)
f(kTs)
0 Ts 4Ts t 2π/Ts
0 ω
F(Ω)
f[k]
0 1 4 Ω
k 0 2π
Differences DTFT-CTFT
• The DTFT is periodic with period Ωs=2π (or ωs=2π/Ts)
• The discrete-time exponential ejΩk has a unique waveform only for values of
Ω in a continuous interval of 2π
• Numerical computations can be conveniently performed with the Discrete
Fourier Transform (DFT)
DTFS
• Discrete Time Fourier Series
• Discrete time periodic sequences of period N0
– Fundamental frequency
Ω 0 = 2π / N 0
N 0 −1 N 0 −1 2π
jr k
1 1
fk =
N0
∑ r
F
k =0
e jr Ω0 k
=
N0
∑Fe
k =0
r
N0
2π
Ω0 =
N0
• The DFT transforms N0 samples of a discrete-time signal to the same number of
discrete frequency samples
• The DFT and IDFT are a self-contained, one-to-one transform pair for a length-N0
discrete-time signal (that is, the DFT is not merely an approximation to the DTFT as
discussed next)
• However, the DFT is very often used as a practical approximation to the DTFT
DFT
0 k
N0
zero padding
F(Ω)
0 2π 4π r
2π/N0
Discrete Cosine Transform (DCT)
• Operate on finite discrete sequences (as DFT)
• A discrete cosine transform (DCT) expresses a sequence of finitely many
data points in terms of a sum of cosine functions oscillating at different
frequencies
• DCT is a Fourier-related transform similar to the DFT but using only real
numbers
• DCT is equivalent to DFT of roughly twice the length, operating on real data
with even symmetry (since the Fourier transform of a real and even function
is real and even), where in some variants the input and/or output data are
shifted by half a sample
• There are eight standard DCT variants, of which four are common
• Strong connection with the Karunen-Loeven transform
– VERY important for signal compression
DCT
• DCT implies different boundary conditions than the DFT or other related
transforms
• A DCT, like a cosine transform, implies an even periodic extension of the
original function
• Tricky part
– First, one has to specify whether the function is even or odd at both the left and
right boundaries of the domain
– Second, one has to specify around what point the function is even or odd
• In particular, consider a sequence abcd of four equally spaced data points, and say that
we specify an even left boundary. There are two sensible possibilities: either the data is
even about the sample a, in which case the even extension is dcbabcd, or the data is
even about the point halfway between a and the previous point, in which case the even
extension is dcbaabcd (a is repeated).
Symmetries
DCT
N 0 −1
⎡π ⎛ 1⎞ ⎤
Xk = ∑ xn cos ⎢ ⎜ n + ⎟ k ⎥ k = 0,...., N 0 − 1
n=0 ⎣ N0 ⎝ 2⎠ ⎦
2 ⎧1 N 0 −1
⎡π k ⎛ 1 ⎞⎤ ⎫
xn = ⎨ X 0 + ∑ X k cos ⎢ ⎜ k + ⎟ ⎥ ⎬
N0 ⎩2 k =0 ⎣ N0 ⎝ 2 ⎠⎦ ⎭
Signal domain
Frequency domain
Gaussian
rect
sinc function
Images vs Signals
1D 2D
• Signals • Images
• Frequency • Frequency
– Temporal – Spatial
– Spatial
• Space/frequency characterization of
• Time (space) frequency 2D signals
characterization of signals
• Reference space for
• Reference space for
– Filtering
– Filtering
– Changing the sampling rate
– Up/Down sampling
– Signal analysis
– Image analysis
– ….
– Feature extraction
– Compression
– ….
2D spatial frequencies
• 2D spatial frequencies characterize the image spatial changes in the
horizontal (x) and vertical (y) directions
– Smooth variations -> low frequencies
– Sharp variations -> high frequencies
ωx=1
ωy=0 ωx=0
ωy=1
x
2D Frequency domain
Large horizontal and
vertical frequencies
ωy
correspond sharp
Large vertical grayscale changes in
frequencies correspond both directions
to horizontal lines
ωx
Small horizontal and
vertical frequencies Large horizontal
correspond smooth frequencies correspond
grayscale changes in to vertical lines
both directions
Vertical grating
ωy
0 ωx
Double grating
ωy
0 ωx
Smooth rings
ωy
ωx
2D box
2D sinc
Margherita Hack
∞
1
1D F (Ω) = ∑
k =−∞
f [k ]e − j Ωk
, f [k ] =
2π ∫π F (Ω)e jΩk dt
2
ω x = 2π u
ω y = 2π v
+∞
fˆ ( u , v ) = ∫ f ( x, y ) e − j 2π ( ux + vy ) dxdy
−∞
+∞
1
f ( x, y ) = ∫ fˆ ( u , v ) e j 2π ( ux + vy ) ( 2π ) dudv =
2
4π 2 −∞
+∞
1 ˆf ( u , v ) e j 2π ( ux + vy ) ( 2π )2 dudv
=
4π 2 ∫
−∞
2D Continuous Fourier Transform
• 2D Continuous Fourier Transform (notation 2)
+∞
fˆ ( u , v ) = ∫ f ( x, y ) e − j 2π ( ux + vy ) dxdy
−∞
+∞
f ( x, y ) = ∫ fˆ ( u , v ) e j 2π ( ux + vy ) dudv =
−∞
∞ ∞ ∞ ∞
2
∫∫ f ( x, y ) dxdy = ∫∫
2
fˆ (u , v) dudv Plancherel’s equality
−∞ −∞ −∞ −∞
2D Discrete Fourier Transform
The independent variable (t,x,y) is discrete
N 0 −1 N 0 −1 N 0 −1
Fr = ∑
k =0
f [ k ]e − jrΩ0 k F [u , v] = ∑∑
i =0 k =0
f [i, k ]e − jΩ0 ( ui + vk )
N 0 −1 N 0 −1 N 0 −1
1
∑∑
1
f N0 [k ] =
N0
∑
r =0
Fr e jrΩ0 k f N0 [i, k ] = 2
N0 u =0 v =0
F [u , v]e jΩ0 ( ui + vk )
2π 2π
Ω0 = Ω0 =
N0 N0
Delta
• Sampling property of the 2D-delta function (Dirac’s delta)
∫ δ ( x − x , y − y ) f ( x, y)dxdy = f ( x , y )
−∞
0 0 0 0
∞ ∞
F {δ ( x, y )} = ∫ ∫ δ ( x , y ) e − j 2π ( ux + vy )
dxdy = 1
−∞ −∞
∞ ∞
F {δ ( x − x0 , y − y0 )} = ∫ ∫ δ ( x − x , y − y ) e − j 2π ( ux + vy )
dxdy = e − j 2π ( ux + vy )
0 0 shifting
0 0 property
−∞ −∞
Constant functions
• Inverse transform of the impulse function
∞ ∞
F −1 {δ (u , v)} = ∫ ∫ δ (u , v ) e j 2π ( ux + vy )
dudv =e j 2π (0 x + v 0)
=1
−∞ −∞
k ( x, y ) = 1 ∀x, y
∞ ∞
F {k } = ∫ ∫ e − j 2π ( ux + vy )
dxdy = δ (u , v)
−∞ −∞
Trigonometric functions
• Cosine function oscillating along the x axis
– Constant along the y axis
s( x, y ) = cos(2π fx)
∞ ∞
F {cos(2π fx)} = ∫ ∫ cos(2π fx ) e − j 2π ( ux + vy )
dxdy =
−∞ −∞
∞ ∞
⎡ e j 2π ( fx ) + e − j 2π ( fx ) ⎤ − j 2π (ux + vy )
= ∫ ∫⎢ ⎥e dxdy
−∞ −∞ ⎣ ⎦
2
∞ ∞
1
= ∫ ∫ ⎡⎣e− j 2π (u − f ) x + e− j 2π (u + f ) x ⎤⎦ e− j 2π vy dxdy =
2 −∞ −∞
∞ ∞ ∞
1 1
= ∫ e− j 2π vy dy ∫ ⎣⎡e− j 2π (u − f ) x + e− j 2π (u + f ) x ⎦⎤ dx = 1 ∫ ⎣⎡e− j 2π (u − f ) x + e− j 2π ( u + f ) x ⎦⎤ dx =
2 −∞ −∞
2 −∞
1
[δ (u − f ) + δ (u + f )]
2
Vertical grating
ωy
0 ωx
-2πf 2πf
Ex. 1
Ex. 2
Ex. 3
Magnitudes
Examples
Properties
■ Linearity af ( x, y ) + bg ( x, y ) ⇔ aF (u , v) + bG (u , v)
− j 2π ( ux0 + vy0 )
■ Shifting f ( x − x0 , y − x0 ) ⇔ e F (u, v)
■ Modulation e j 2π ( u0 x + v0 y ) f ( x, y ) ⇔ F (u − u0 , v − v0 )
■ Convolution f ( x, y ) * g ( x, y ) ⇔ F (u , v)G (u , v)
■ Multiplication f ( x, y ) g ( x, y ) ⇔ F (u , v) * G (u , v)
■ Separability f ( x, y ) = f ( x) f ( y ) ⇔ F (u, v) = F (u ) F (v)
Separability
1. Separability of the 2D Fourier transform
– 2D Fourier Transforms can be implemented as a sequence of 1D Fourier
Transform operations performed independently along the two axis
∞ ∞
F (u , v) = ∫∫
−∞ −∞
f ( x, y )e − j 2π (ux + vy ) dxdy =
∞ ∞ ∞ ∞
∫∫ ∫e dy ∫ f ( x, y )e− j 2π ux dx =
− j 2π ux − j 2π vy − j 2π vy
f ( x, y ) e e dxdy =
−∞ −∞ −∞ −∞
∞
= ∫ F (u, y)e
− j 2π vy
dy = F ( u, v )
−∞
∞ ∞ ∞ ∞
∫∫ h( x ) g ( y ) e − j 2π ux − j 2π vy
e dxdy = ∫ g ( y)e − j 2π vy
dy ∫ h( x)e− j 2π ux dx =
−∞ −∞ −∞ −∞
= H (u ) G (v )
f ( x, y ) = h ( x ) g ( y ) ⇒ F ( u , v ) = H ( u ) G ( v )
2D Fourier Transform of a Discrete function
• Fourier Transform of a 2D a-periodic signal defined over a 2D discrete grid
– The grid can be thought of as a 2D brush used for sampling the continuous
signal with a given spatial resolution (Tx,Ty)
∞
1
1D F (Ω ) = ∑
k =−∞
f [k ]e − jΩk , f [ k ] =
2π ∫ F (Ω)e jΩk dt
2π
+∞ +∞ − j ( k1Ω x + k2 Ω y )
2D F (Ω x , Ω y ) = ∑ ∑
k1 =−∞ k2 =−∞
f [k1 , k2 ]e
1 j ( k1Ω x + k2 Ω y )
f [k ] =
4π 2 ∫π ∫π
2 2
F (Ω x , Ω y )e d ΩxΩ y
1/ 2 1/ 2
f [k1 , k2 ] = ∫ ∫
−1/ 2 −1/ 2
F (u , v)e − j 2π ( k1u + k2v ) dudv
• The integration interval for the inverse transform has width=1 instead of 2π
– It is quite common to choose
−1 1
≤ u, v <
2 2
Properties
• Periodicity: 2D Fourier Transform of a discrete a-periodic signal is periodic
– The period is 1 for the unitary frequency notations and 2π for normalized
frequency notations.
– Proof (referring to the firsts case)
∞ ∞
F (u + k , v + l ) = ∑∑
m =−∞ n =−∞
f [m, n]e
− j 2π ( ( u + k ) m + ( v + l ) n )
1 1
∞ ∞
Arbitrary
= ∑∑
m =−∞ n =−∞
f [m, n]e
− j 2π ( um + vn ) − j 2π km − j 2π ln
e e
integers ∞ ∞
= ∑∑
m =−∞ n =−∞
f [m, n]e − j 2π (um + vn )
= F (u , v)
Properties
• Linearity
• shifting
• modulation
• convolution
• multiplication
• separability
• energy conservation properties also exist for the 2D Fourier Transform of
discrete signals.
• NOTE: in what follows, (k1,k2) is replaced by (m,n)
2D DTFT Properties
∑∑ f [m, n] = ∫ ∫
2 2
■ Energy conservation F (u, v) dudv
m =−∞ n =−∞ −1/ 2 −1/ 2
Impulse Train
∞ ∞
combM , N [m, n] = ∑ ∑ δ [m − kM , n − lN ]
k =−∞ l =−∞
comb2 [n]
1
n
Appendix
2D-DTFT: delta
∞ ∞
F (u , v) = ∑ ∑
m =−∞ n =−∞
⎡
⎣δ [ m, n ]e
− j 2π ( um + vn )
⎤
⎦ = e
− j 2π ( u 0 + v 0 )
=1
2D DT Fourier Transform: constant
■ Fourier Transform of 1
f [k , l ] = 1, ∀k , l
∞ ∞
F [u , v] = ∑ ∑
k =−∞ l =−∞
⎡
⎣1e − j 2π ( uk + vl )
⎤=
⎦
∞ ∞
= ∑ ∑ δ (u − k , v − l )
k =−∞ l =−∞
periodic with period 1
along u and v
To prove: Take the inverse Fourier Transform of the Dirac delta function and use the fact that
the Fourier Transform has to be periodic with period 1.