36
Technion, CS department, SIPC 236327 Spring 2015 Tutorial 8 Discrete Signals and Systems 1/39

Discrete signals and systemswebcourse.cs.technion.ac.il/236327/Spring2015/ho/WCFiles/...Discrete Signals and Systems 1/39 •Linear 𝐻1𝐷 + = 𝐻1𝐷 + 𝐻1𝐷 •Space invariant

Embed Size (px)

Citation preview

Technion, CS department, SIPC 236327

Spring 2015

Tutorial 8Discrete Signals and Systems

1/39

• Linear

𝐻1𝐷 𝑎𝑥 𝑛 + 𝑏𝑤 𝑛 = 𝑎𝐻1𝐷 𝑥 𝑛 + 𝑏𝐻1𝐷 𝑤 𝑛

• Space invariant

For 𝐻1𝐷 𝑥 𝑛 = 𝑦 𝑛 : 𝐻1𝐷 𝑥 𝑛 − 𝑛0 = 𝑦 𝑛 − 𝑛0

Discrete LSI system

2/39

𝐻1𝐷 nx y n

• Linear𝐻2𝐷 𝑎𝑓 𝑚, 𝑛 + 𝑏𝑤 𝑚, 𝑛 = 𝑎𝐻2𝐷 𝑓 𝑚, 𝑛 + 𝑏𝐻2𝐷 𝑤 𝑚, 𝑛

• Space invariant𝐻2𝐷 𝑓 𝑚, 𝑛 = 𝑔 𝑚, 𝑛

yields𝐻2𝐷 𝑓 𝑚 −𝑚0, 𝑛 − 𝑛0 = 𝑔[𝑚 −𝑚0, 𝑛 − 𝑛0]

Discrete LSI system

3/39

nmg , nmf , 𝐻2𝐷

• A system is defined by its impulse response

Discrete LSI system

4/39

nhxknhkxnyk

*

𝛿[𝑛]

𝑛

• Infinite support• Related to DTFT

(Do not confuse with DFT)

Cyclic convolution

5/39

• Finite support• 𝑦 = 𝑇𝑐𝑥

• Related to DFT• Efficient implementation

(Linear) Convolution

knhkxnhxk

* Nknhkxnhx

N

k

mod

1

0

1

2

1

0

0121

1012

2301

1210

1

2

1

0

Nx

Nx

x

x

hhNhNh

NhhNhNh

hhhh

hhNhh

Ny

Ny

y

y

Infinite support Continuous

Finite support Discrete

Discrete Fourier Transform (DFT)

6/39

)(txFourier)(tx

][nx ][nxDFT

Infinite support

Continuous

Finite support

Discrete

:המקדמים מחזוריים•

.[N/2,N/2-1-]ניתן להתייחס לתחום[N-1,0]לכן במקום להתייחס לתחום •

7/39

12 /

0

12 /

0

1: [ ]

1: [ ]

Ni kn N

n

Ni kn N

k

DFT X k x n eN

Inverse DFT x n X k eN

...2,1,0, mmNkXkX

Discrete Fourier Transform (DFT)

ExampleDFT

8/39

0 50 100-1

-0.5

0

0.5

1

t

x[t]

-50 0 500

5

10

15

20

k|X

[k]|

ExamplesDFT

9/39

0

0 0

221

0

0

, 0, ..., 1

1 1knknN

j jN N

n

DFT n n n N

X k n n e eN N

0 0

0 00 0

2 2

0 0

0

2 22 2 21 1

0 0

0 0

2 2 1cos , 0 1 cos

2

1 1 1 1

2 2

2

k kj n j n

N N

k k k kk k knN Nj n j n j j n j n

N N N N N

n n

k kDFT n k N x n n e e

N N

X k e e e e eN N

Nk k k k

DFT and LSI Systems

10/39

nhxny nx

nh kX

kH

kHkXkY

• Noisy image of size 256X256

Im_out[m,n]=Im_in[m,n]+noise[m,n]

• Harmonic noise:

• f = 1/(8 pixels)

• Amplitude A and phase φ are random and independent for each line.

Example – Discrete Frequency Filtration

11/39

mm

fnAnmnoise 2cos],[

Example – Added Noise in Line 100

12/39

rad

A

325.1

37.22

100

100

Example – Discrete Frequency Filtration

13/39

Example – Discrete Frequency Filtration: Smoothing

14/39

Example – Discrete Frequency Filtration:Smoothing vs Median (8 pixels)

15/39

No noise but image is blurred

• DFT of the noise in line i

Example – Discrete Frequency Filtration

16/39

2

2 32

32( , ) cos 2 cos 2

256

3232( , )00

ii

i i i i

Niki

N ii

Noise i n A fn A nN

N

A e kA e kDFT Noise i nelseelse

• Design an LSI filter– Such filter multiplies each frequency with a complex

number.

– Can handle each frequency separately.

• In this example, we want to handle frequencies 32 and -32.– Notch filter: attenuates specific frequencies.

Example – Discrete Frequency Filtration

17/39

Example – Discrete Frequency Filtration

18/39

Original signal in

frequency domainFiltered signal in

frequency domain

• The noise was significantly removed.

• Original image was not fully restored– We cannot restore the

attenuated frequencies

Example – Discrete Frequency Filtration

19/39

Example – Discrete Frequency Filtration

20/39

Smoothing filter

of 8 pixelsNotch filter

• Filter in freq. domain:

Filter=ones(1,256);

Filter(32+1)=0;

Filter(224+1)=0;

• Filtration:

For k=1:size(I,1),

Y=fft(I(k,:)).*Filter;

I(k,:)=ifft(Y);

end

Example –Frequency Filtration - Implementation

21/39

Notch filter in freq. domain

Technion, CS department, SIPC 236327

Spring 2015

Discrete Signals and SystemsPart II: 2D

22/39

2D convolution:

2D - Definitions

23/39

mnhxmny ,*, mnx , mnh ,

k l

lnkmhlkxnmhx ,,,*

• Cyclic 2D-convolution:

• 2D DFT:

24/39

nmhxnmy ,, nmx , nmh ,

lkX ,

lkH ,

lkHlkXlkY ,,,

1

0

1

0

modmod,,,

M

k

N

l

NMlnkmhlkxnmhx

1

0

1

0

22

,,

1,

M

m

N

n

N

nli

M

mki

lkeenmx

MNnmxDFT

2D - Definitions

• Matrix form of 1D DFT that operates on a vector 𝑥:

• 2D-DFT can be implemented as:

where 𝑋 is a matrix.

• For a separable input signal:

25/39

1DDFT x Dx

2

T

DDFT X DXD

2 1 1 1 2,D D Dk l k lDFT X DFT x DFT x

2D - Notes

1 2,X m n x m x n

• Noisy image 512X512

• The noise:Add 100 gray levels for all 16i lines

Example

26/39

mean 4X4

Example

27/39

Noisy image Average-filter resultoriginal + noise

mean 16X16

Example

28/39

Noisy image Average filteroriginal + noise

• How does the noise look like in the frequency domain?

Example

29/39

1 , 16 16 ,

,0 ,

for n k or m k kr n m

else

Before Frequency Filtration

DFT of image + noise

30/39

31/39

Before Frequency Filtration (zoom-in)

• Filter implementation in the freq. domain:

H=ones(512,512);for n=1:32:512

H(n,1) = H(1,n) = 0;endH(1,1) = 1;

• Image filtration:out = ifft( fft(img).*H );

Example

32/39

Image after freq. filtration

33/39

After Frequency Filtration (zoom-in)

Image Filtration

34/39

000

011

000

h

000

110

000

h

000

101

000

2

1h

• Roberts

• Prewitt

• Sobel

Edge Detection of The Image 𝐴

35/39

AGAGyx

*01

10*

10

01

AGAGyx

*

111

000

111

*

101

101

101

AGAGyx

*

121

000

121

*

101

202

101

22),(),(),( nmGnmGnmG

yx

Edge detection of Image A

36/44

Original Roberts

SobelPrewitt