Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 16

Discrete

Fourier
Transform
Discrete Fourier Transform
𝑪𝑶𝑴𝑷𝑳𝑬𝑿 𝑭𝑶𝑼𝑹𝑰𝑬𝑹 𝑺𝑬𝑹𝑰𝑬𝑺
𝒇

𝑓 𝑥 = ෍ 𝒄𝒏 𝑒 𝑖𝑤𝑛 𝑥
𝑛=−∞

1 𝜏+2L
𝒄𝒏 = න 𝑓 𝑥 𝑒 −𝑖𝒘𝒏 𝑥 𝑑𝑥
2L 𝜏
𝒙
𝑛𝜋
𝒘𝒏 = 𝑛 = 0, ±1, ±2, ±3, ⋯
𝐿
𝒇

𝑭𝑰𝑵𝑰𝑻𝑬 𝑭𝑶𝑼𝑹𝑰𝑬𝑹 𝑺𝑬𝑹𝑰𝑬𝑺 The (finite) discrete Fourier series


𝑁−1

𝑓 𝑥 =෍
𝒙 𝑛=0
Discrete Fourier Transform
Consider a perodic function 𝑓 defined on the The (finite) discrete Fourier
interval [0, 2𝜋]. 𝑓(𝑥) can be written in a series
complex Fourier series, ∞

2𝜋 𝒇 𝒙 = ෍ 𝒄𝒏 𝒆𝒊 𝒏𝒙
𝑓 𝑥 = ෍ 𝑐𝑛 𝑒 𝑖 𝑛 𝑤 𝑥 where 𝑤 = 2𝐿
. 𝒏=−∞
𝑛=−∞
using these N terms gives us
Now consider the function values at N equally
𝑵−𝟏
spaced points
𝒇 𝒙 = ෍ 𝒄𝒏 𝒆𝒊 𝒏𝒙
𝒇𝟎 𝒇𝟏 𝒇𝟐 𝒇𝑵−𝟏 𝒏=𝟎

is called the discrete Fourier


𝒙𝟎 𝒙𝟏 𝒙𝟐 𝒙𝑵−𝟏 transform (DFT) of the
function 𝑵−𝟏
𝑻 sampling rate
2𝜋 𝒇 𝒙𝒌 = ෍ 𝒄𝒏 𝒆𝒊 𝒏 𝒙𝒌
𝑇= 𝒏=𝟎
𝑁 𝑘 = 0, 1, 2, . . , 𝑁 − 1
𝑥𝑘 = 𝑘𝑇, 𝑘 = 0, 1, 2, … 𝑁 − 1.
𝑵−𝟏

𝑓𝑘 = 𝑓 𝑘𝑇 , 𝑘 = 0, 1, 2, … 𝑁 − 1. 𝒇 𝒙𝒌 = ෍ 𝒄𝒏 𝒆𝒊 𝒏𝒌𝑻

𝒏=𝟎
Discrete Fourier Transform
𝑵−𝟏
In expanded form: 𝑘 = 0, 1, 2, … 𝑁 − 1
𝒇 𝒙𝒌 = ෍ 𝒄𝒏 𝒆𝒊 𝒏 𝒙𝒌
𝒌(𝟏) v
𝒌 (𝟐) 𝒌(𝑵−𝟏)
𝒇𝒌 = 𝒄𝟎 + 𝒄𝟏 𝜶𝑵 + 𝒄𝟐 𝜶𝑵 + ⋯ + 𝒄𝑵−𝟏 𝜶𝑵
𝒏=𝟎

𝑘 = 0, 1, 2, . . , 𝑁 − 1
So we have N-1 equations
𝑵−𝟏 𝒇𝟎 = 𝒄𝟎 + 𝒄𝟏 + 𝒄𝟐 + ⋯ + 𝒄𝑵−𝟏 𝒌= 𝟎
𝒊 𝒏𝒌𝑻
𝒇 𝒙 𝒌 = ෍ 𝒄𝒏 𝒆 𝒇𝟏 = 𝒄𝟎 + 𝒄𝟏 𝜶𝟏𝑵 + 𝒄𝟐 𝜶𝟐𝑵 + ⋯ + 𝒄𝑵−𝟏 𝜶𝑵−𝟏 𝒌=𝟏
𝑵
𝒏=𝟎 v 𝟐(𝑵−𝟏)
𝒇𝟐 = 𝒄𝟎 + 𝒄𝟏 𝜶𝟐𝑵 + 𝒄𝟐 𝜶𝟒𝑵 + ⋯ + 𝒄𝑵−𝟏 𝜶𝑵 𝒌=𝟐

⋮ ⋮ ⋮ 𝑵−𝟏 𝟐 ⋮
Let : 𝜶𝑵 = 𝒆𝒊 𝑻 𝒇𝑵−𝟏 = 𝒄𝟎 + 𝒄𝟏 𝜶𝑵−𝟏
𝑵 +
𝟐(𝑵−𝟏)
𝒄𝟐 𝜶𝑵 + ⋯ + 𝒄𝑵−𝟏 𝜶𝑵 𝒌=𝑵−𝟏

𝑵−𝟏
In matrix form
𝒇 𝒙𝒌 = ෍ 𝒄𝒏 𝜶𝒌𝑵 𝒏
𝒏=𝟎 𝑓0 1 1 1 ⋯ 1 𝑐0
𝑓1 1 𝜶𝑵 𝜶𝟐𝑵 ⋯ 𝜶𝑵−𝟏
𝑵 𝑐1
𝟐(𝑵−𝟏)
𝑓2 = 1 𝜶𝟐𝑵 𝜶𝟒𝑵 v ⋯ 𝜶𝑵 𝑐2
⋮ ⋮ ⋮ ⋮ ⋱ ⋮ ⋮
𝑓𝑁−1 1 𝑵−𝟏
𝜶𝑵
𝟐(𝑵−𝟏)
𝜶𝑵 ⋯ (𝑵−𝟏)(𝑵−𝟏) 𝑐𝑁−1
𝜶𝑵

𝑭𝑵
Discrete Fourier Transform
In matrix form
1 1 1 ⋯ 1
𝑓0
1 𝜶𝑵 𝜶𝟐𝑵 ⋯ 𝜶𝑵−𝟏
𝑐0 𝑐0 𝑓0
𝑓1 𝑵 𝑐1
𝑓2 = 1 𝜶𝟐𝑵 𝜶𝟒𝑵v ⋯ 𝟐(𝑵−𝟏)
𝜶𝑵 𝑐2 𝑐1 𝟏 𝑓1
⋮ ⋮ ⋮ ⋮ ⋱ ⋮ ⋮ 𝑐2 = v 𝑭𝑵 𝑓2
𝑓𝑁−1 1 𝑵−𝟏
𝜶𝑵
𝟐(𝑵−𝟏)
𝜶𝑵 ⋯ (𝑵−𝟏)(𝑵−𝟏)
𝜶𝑵
𝑐𝑁−1
⋮ 𝑵

𝑭𝑵 𝑐𝑁−1 𝑓𝑁−1

𝑓0 𝑐0 𝑓0 𝑐0
𝑓1 𝑐1 𝑓1 𝑐1
𝑓2 = 𝐹𝑁 𝑐2 v 𝐹𝑁−1 𝑓2 = 𝑐2
⋮ ⋮ ⋮ ⋮
𝑓𝑁−1 𝑐𝑁−1 𝑓𝑁−1 𝑐𝑁−1

𝟏
𝑭𝑵 𝑭𝑵 = 𝑭𝑵 𝑭𝑵 = 𝐍𝐈 𝑭−𝟏
𝑵 = 𝑭𝑵
v 𝑵
𝑭𝑵 is the matrix consisting of the complex conjugates of the entries of 𝑭𝑵
Discrete Fourier Transform
Example: 𝑐0 𝑓0 𝟐𝝅
𝑐1 𝑓1 𝑻=
Find the finite Fourier series 𝑐2
𝟏 𝑵
= 𝑭 𝑓2
for the following pieces of ⋮ 𝑵 𝑵
⋮ 𝜶𝑵 = 𝒆𝒊 𝑻
data: 𝑐𝑁−1 𝑓𝑁−1
𝜋 3𝜋
𝑓 0 = 0, 𝑓 = 2, 𝑓 𝜋 = 4, 𝑓 =6 v
2 2 1 1 1 ⋯ 1
1 𝜶𝑵 𝜶𝟐𝑵 ⋯ 𝜶𝑵−𝟏
𝑵
𝟐(𝑵−𝟏)
𝑵=𝟒 𝑻 = 𝟐𝝅/𝟒 𝐹𝑁 = 1 𝜶𝟐𝑵 𝜶𝟒𝑵 ⋯ 𝜶𝑵
⋮ ⋮ ⋮ ⋱ ⋮
𝛼𝑁 = 𝑒 (𝜋/2)𝑖 1 𝑵−𝟏
𝜶𝑵
𝟐(𝑵−𝟏)
𝜶𝑵 ⋯ 𝜶 (𝑵−𝟏)(𝑵−𝟏)
𝑵
𝜋 𝜋
𝛼𝑁 = cos + 𝑖 sin = 𝑖
2 2
𝑐0 1 1 1 1 0 3
𝑐1 𝟏 1 −𝑖 −1 𝑖 2
1 1 1 1 𝑐2 =
𝟒 1 −1 1 −1 4 = −1 + 𝑖
1 𝑖 −1 −𝑖 −1
𝐹4 = 𝑐3 1 𝑖 −1 −𝑖 6
1 −1 1 −1 −1 − 𝑖
1 −𝑖 −1 𝑖
𝑓0 𝑐0
Remark
1 1 1 1 𝑓1 𝑐1
1 −𝑖 −1 𝑖 Given 𝑓2 = 𝐹𝑁 𝑐2
𝑭𝟒 = 𝑐0 , ⋯ , 𝑐𝑁−1 Find ⋮
1 −1 1 −1 ⋮
1 𝑖 −1 −𝑖 𝑓0 , ⋯ 𝑓𝑁−1 𝑓𝑁−1 𝑐𝑁−1
Discrete Fourier Transform
Example: Find the finite Fourier series 3
for the following pieces of
𝑐 = −1 + 𝑖
data: 𝜋 3𝜋 −1
𝑓 0 = 0, 𝑓 = 2, 𝑓 𝜋 = 4, 𝑓 =6 −1 − 𝑖
2 2

Remark 𝑐0 𝑓0
𝑐1 𝟏 𝑓1
Given 𝑓0 , ⋯ , 𝑓𝑁−1 𝑐2 f = [0, 2, 4, 6];
= 𝑭 𝑓2
Find 𝑐0 , ⋯ 𝑐𝑁−1 ⋮ 𝑵 𝑵 c = fft(f) / N

𝑐𝑁−1 𝑓𝑁−1

𝑓0 𝑐0
Remark
𝑓1 𝑐1 c = [3, -1+i, -1, -1-i];
Given 𝑓2 = 𝑭𝑵 𝑐2 f = ifft(c) * N
𝑐0 , ⋯ , 𝑐𝑁−1 Find ⋮ ⋮
𝑓0 , ⋯ 𝑓𝑁−1 𝑓𝑁−1 𝑐𝑁−1

Remark Because of the nature of these matrix 𝑭𝑵 , these multiplications can be done in a very
computationally efficient manner, using the Fast Fourier Transform (FFT) ,which will be
discussed later. [J.W.Cooley and J.W.Tukey]
Discrete Fourier Transform
Example: Frequency Spectrum

The complex Fourier series


for𝑓 𝑥 = 𝑥, 0 < 𝑥 < 2𝜋

is ∞
𝒊 𝑖𝑛𝑥
𝑓 𝑡 =𝜋+ ෍ 𝑒
𝑛=−∞
𝒏
𝑛≠0

clear; clc; close all


N=12;
k=N-1;
nn=[0:5];
cnr0 = pi; cni0 =0;
for n=1:k
cnr(n) = 0; cni(n)=1/n;
end
amplitude = sqrt(cnr.*cnr+cni.*cni);
amplitude0 = sqrt(cnr0.*cnr0+cni0.*cni0);
amplitude =[amplitude0 , amplitude];
stem(nn,amplitude(1:6),'filled','b'); grid on; hold on

f=@(x) x;
T = 2*pi/N;
x_v = [0:T:2*pi-T];
f_v = f(x_v);
F_v = fft(f_v)/N;
F_v = abs(F_v);
stem(nn,F_v(1:6),'filled','r'); grid on F_v = fft(f_v)/N;
title(['N = ',num2str(N)])
legend('Complex FS','using FFT'); hold off
Applications
1)Filtering
2)Image Compression
Filtering
filter is a popular method for eliminating Create N points & plot
clear; clc; close all
unwanted waves from a record. Filters N=1000; a=0; b=1;
h=(b-a)/(N-1);
play an important role in the analysis of t=a:h:b;
x=sin(2*pi*40*t)+sin(2*pi*100*t);
data. plot(t,x)
FFT and Freq. spectrum
Example: Y=fft(x,N);
PSD=Y.*conj(Y)/N;
freq=1/(h*N)*(0:N);
consider 𝑓 𝑥 = sin 2𝜋 ∗ 40𝑡 + sin(2𝜋 ∗ 100𝑡) L=1:150;
figure
plot(freq(L),PSD(L))
Add noise to signal
xwnoise = x + 3*(-1+
2*rand(size(t)));
plot(t,x,'r',t,xwnoise,'b')
FFT the noised signal
Y2=fft(xwnoise,N);
PSD2=Y2.*conj(Y2)/N;
freq2=1/(h*N)*(0:N);
L2=1:N;
figure
plot(freq2(L2),PSD2(L2))
Filter
index_vec =PSD2>50;
Y3 = Y2.*index_vec;
PSD3=Y3.*conj(Y3)/N;
sparse(PSD3)
freq3=1/(h*N)*(0:N);
L3=1:N;
figure
plot(freq3(L3),PSD3(L3))
IFFT
x3 = ifft(Y3,N);
plot(t,x,'r',t,x3,'b')
Applications
1)Filtering
2)Image Compression
Image Compression
An image is composed of elements called pixels.
Each pixel is assigned an intensity.
A small image typically has around 256^2 =
65,536 pixels while a high resolution image
often has 5 to 10 million pixels.
The intensity can be an integer or a vector
of integers.

u ( x, y ) :   R Grayscale images
The intensity is an integer
Two-Dimensional FFTs
the (complex) Fourier coefficient for the two-
dimensional function f(x,y) is

0 2 3 −1 + 𝑖
𝑓= 𝑓=
4 6 −1 −1 − 𝑖
v
f = [0, 2; 4, 6]; c = [3, -1+i;-1, -1-i];
c = fft2(f) / N^2 f = ifft2(c) * N^2
Image Compression
Image compression is a type of data
Read the image
compression applied to digital images, to clear; clc; close all
reduce their cost for storage or u = imread('goldhill512.png');
%u = imread('peppers256.png');
transmission. figure; imshow(u);title('original image');
Example: N = size(u,1)
FFT2 and plot
u_hat = fft2(u);
u_hat1 = log(abs(u_hat));
surf(u_hat1);
compress
ind = 8 < u_hat1 ;%< 10.000001;
u_hat2 = mat2gray(ind).*u_hat1;
surf(u_hat2);
ind_d = double(ind);
ind_z = sparse(ind_d);
u_hat_low = ind_d.*double(u_hat);
IFFT2 and display
262144 numbers 118071 numbers u2 = ifft2(u_hat_low);
u3 =mat2gray(u2);
figure; imshow(u3);
Calculate percintage
[i,j,s] = find(ind_z);
perc = 100*length(i)/N^2
title(['percentage =',num2str(perc),'%'])

8245 numbers
Image Compression

Color
FAST Fourier
Transform
(FFT)

You might also like