Digital Filters

39
Digital Filters Digital Filters Part A characterization Part A characterization and analysis and analysis

description

Digital Filters. Part A characterization and analysis. - PowerPoint PPT Presentation

Transcript of Digital Filters

Page 1: Digital Filters

Digital FiltersDigital Filters

Part A characterization and Part A characterization and analysisanalysis

Page 2: Digital Filters

““As soon as we started programming, we found As soon as we started programming, we found out to our surprise that it wasn't as easy to get out to our surprise that it wasn't as easy to get programs right as we had thought. Debugging programs right as we had thought. Debugging had to be discovered. I can remember the exact had to be discovered. I can remember the exact instant when I realized that a large part of my life instant when I realized that a large part of my life from then on was going to be spent in finding from then on was going to be spent in finding mistakes in my own programs.”mistakes in my own programs.”

Maurice Wilkes (a pioneering British computer scientist, winner of Maurice Wilkes (a pioneering British computer scientist, winner of the 1967 Turing Award, developed the first stored-program the 1967 Turing Award, developed the first stored-program computer in 1949, invented the concept of microprogramming in computer in 1949, invented the concept of microprogramming in 1951, credited with originating the fundamental software concepts 1951, credited with originating the fundamental software concepts of symbolic labels, macros, and subroutine libraries; from of symbolic labels, macros, and subroutine libraries; from wikipedia)wikipedia)

Page 3: Digital Filters

What have we seen so far?What have we seen so far?

So far we have seen…So far we have seen…• Box filterBox filter

Moving average filterMoving average filter Example of a lowpassExample of a lowpass

• passes low frequenciespasses low frequencies small, gradual changes in the signal are small, gradual changes in the signal are

passedpassed higher frequencies are attenuated higher frequencies are attenuated

(reduced/removed/suppressed)(reduced/removed/suppressed)

Page 4: Digital Filters

Applied by cross correlation (sum Applied by cross correlation (sum of products) of image f and mask hof products) of image f and mask h

If mask is centered about origin, (x,y) If mask is centered about origin, (x,y) in image:in image:

If origin, (x,y), in image is aligned with If origin, (x,y), in image is aligned with (0,0) in mask:(0,0) in mask:

2/

2/

2/

2/

, ,,,,w

wi

h

hj

jihjyixfyxhyxfyxg

1

0

1

0

, ,,,,w

i

h

j

jihjyixfyxhyxfyxg

Page 5: Digital Filters

But how do we know what the But how do we know what the application of an arbitrary mask application of an arbitrary mask

actually does to the image?actually does to the image?

Page 6: Digital Filters

For simplicity, let us just consider 1D signals (e.g., For simplicity, let us just consider 1D signals (e.g., mono audio)mono audio)

Page 7: Digital Filters

Our moving average (box) filterOur moving average (box) filter

Example of a lowpass filter (passes low Example of a lowpass filter (passes low frequencies, attenuates high frequencies, attenuates high frequencies)frequencies)

y[n] = 1/3 x[n-1] + 1/3 x[n]y[n] = 1/3 x[n-1] + 1/3 x[n]

+ 1/3 x[n+1]+ 1/3 x[n+1]

More generally,More generally,

y[n] = h[-1] x[n-1] + h[0] x[n]y[n] = h[-1] x[n-1] + h[0] x[n]

+ h[1] x[n+1]+ h[1] x[n+1]

Page 8: Digital Filters
Page 9: Digital Filters
Page 10: Digital Filters
Page 11: Digital Filters
Page 12: Digital Filters

But what exactly do we mean by But what exactly do we mean by “frequency?”“frequency?”

...sinsin

..

sin

222111 ttty

offsetCD

phase

frequency

amplitude

where

tty

Page 13: Digital Filters

0 5 10 15 20 25 30

-10

-5

0

5

10

sin(x) & 2sin(x)

amplitude (loudness)amplitude (loudness)

Page 14: Digital Filters

0 5 10 15 20 25 30

-10

-5

0

5

10

sin(x) & sin(x+pi/2)

phase (time/space) shiftphase (time/space) shift

Page 15: Digital Filters

0 5 10 15 20 25 30

-10

-5

0

5

10

sin(x) & sin(2x)

frequency (speed)frequency (speed)

Page 16: Digital Filters

0 5 10 15 20 25 30

-10

-5

0

5

10

0.5*sin(x)+sin(3*x+pi/3)+sin(5*x+pi/8)

Page 17: Digital Filters

Input: (Input: (beforebefore)) x(t) = 0.5*sin(t) + sin(3*t+pi/3) + sin(5*t+pi/8)x(t) = 0.5*sin(t) + sin(3*t+pi/3) + sin(5*t+pi/8)Output: (Output: (afterafter)) y(t) = 0.5*sin(t) + sin(3*t+pi/3)y(t) = 0.5*sin(t) + sin(3*t+pi/3)

XLowpass filtersLowpass filters

Page 18: Digital Filters
Page 19: Digital Filters

So how can we determine how our So how can we determine how our moving average filter behaves?moving average filter behaves?

11 point and 51 point moving 11 point and 51 point moving average filters (on the previous slide) average filters (on the previous slide) obviously produce different outputs obviously produce different outputs even when given the same input!even when given the same input!

Answer: By determining how a Answer: By determining how a particular filter responds to an particular filter responds to an impulse (their impulse response impulse (their impulse response function).function).

Page 20: Digital Filters
Page 21: Digital Filters
Page 22: Digital Filters
Page 23: Digital Filters
Page 24: Digital Filters

So given …,h[-1],h[0],h[1],… how So given …,h[-1],h[0],h[1],… how can we plot the impulse response?can we plot the impulse response?

1.1. Perform the z-transform (the discrete Perform the z-transform (the discrete version of the Laplace transform) of h version of the Laplace transform) of h resulting H.resulting H.

2.2. Plot H on the unit circle. The magnitude Plot H on the unit circle. The magnitude of H (abs(H) or |H|) is amplitude and the of H (abs(H) or |H|) is amplitude and the angle of H (arg(H)) is the phase.angle of H (arg(H)) is the phase.

Say we have a 3 point box filter:Say we have a 3 point box filter:

h[-1] = h[0] = h[1] = 1/3.h[-1] = h[0] = h[1] = 1/3.

jjj eeeH 101

3

1

3

1

3

1

Page 25: Digital Filters

So given …,h[-1],h[0],h[1],… how So given …,h[-1],h[0],h[1],… how can we plot the impulse response?can we plot the impulse response?

Say we have an 11 point box filter:Say we have an 11 point box filter:h[-5]=h[-4]=h[-3] =h[-3] =h[-2] =h[-1] =h[0] h[-5]=h[-4]=h[-3] =h[-3] =h[-2] =h[-1] =h[0]

=h[1] =h[2] =h[3] =h[4] =h[5]=1/11.=h[1] =h[2] =h[3] =h[4] =h[5]=1/11.

jj

jjj

jjj

jjj

ee

eee

eee

eeeH

54

321

012

345

11

1

11

111

1

11

1

11

111

1

11

1

11

111

1

11

1

11

1

Page 26: Digital Filters

Frequency response of 3 and 11 Frequency response of 3 and 11 point box filterspoint box filters

0 0.5 1 1.5 2 2.5 3 3.50

0.2

0.4

0.6

0.8

1

1.2

Page 27: Digital Filters

0 0.5 1 1.5 2 2.5 3 3.50

0.2

0.4

0.6

0.8

1

1.2

Page 28: Digital Filters

0 0.5 1 1.5 2 2.5 3 3.5-40

-35

-30

-25

-20

-15

-10

-5

0

5

Frequency response in dB of 3 and Frequency response in dB of 3 and 11 point box filters11 point box filters

Page 29: Digital Filters

dBdB(from http://www.animations.physics.unsw.edu.au/jw/dB.htm)(from http://www.animations.physics.unsw.edu.au/jw/dB.htm)

““The decibel (dB) is used to measure sound The decibel (dB) is used to measure sound level, but it is also widely used in electronics, level, but it is also widely used in electronics, signals and communication. The dB is a signals and communication. The dB is a logarithmic way of describing a ratio. The logarithmic way of describing a ratio. The ratio may be power, sound pressure, voltage ratio may be power, sound pressure, voltage or intensity or several other things.”or intensity or several other things.”

““One decibel is close to the Just Noticeable One decibel is close to the Just Noticeable Difference (JND) for sound level.Difference (JND) for sound level.

Experimentally it was found that a 10 dB Experimentally it was found that a 10 dB increase in sound level corresponds increase in sound level corresponds approximately to a perceived doubling of approximately to a perceived doubling of loudness.”loudness.”

Page 30: Digital Filters

Frequency Frequency response (dB) and response (dB) and phase of 3 and 11 phase of 3 and 11 point box filters.point box filters.

0 0.5 1 1.5 2 2.5 3 3.5-40

-35

-30

-25

-20

-15

-10

-5

0

5

0 0.5 1 1.5 2 2.5 3 3.5-35

-30

-25

-20

-15

-10

-5

0

5

Page 31: Digital Filters

3 point box filter 3 point box filter (blue) vs. 3 point (blue) vs. 3 point gaussian (green)gaussian (green)(normal – left, dB – below)(normal – left, dB – below)

0 0.5 1 1.5 2 2.5 3 3.5-60

-50

-40

-30

-20

-10

0

0 0.5 1 1.5 2 2.5 3 3.50

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1

Page 32: Digital Filters

Frequency response (dB) and Frequency response (dB) and phase of 3 point gaussianphase of 3 point gaussian

0 0.5 1 1.5 2 2.5 3 3.5-60

-50

-40

-30

-20

-10

0

Page 33: Digital Filters

OTHER FILTERSOTHER FILTERS(OTHER THAN LOWPASS)(OTHER THAN LOWPASS)

Page 34: Digital Filters

How can we make these other How can we make these other filters?filters?

Page 35: Digital Filters

Spectral inversion:Spectral inversion:How to make a highpass filter the How to make a highpass filter the

easy way.easy way.

1.1. Change the sign of each sample in Change the sign of each sample in the filter kernel.the filter kernel.

2.2. Add 1 to the sample at the center of Add 1 to the sample at the center of symmetry.symmetry.

• highpasshighpass lowpass lowpass• lowpasslowpass highpass highpass• bandpassbandpass bandreject (stopband) bandreject (stopband)• bandrejectbandreject bandpass bandpass

Page 36: Digital Filters

Spectral inversion:Spectral inversion:How to make a highpass filter the How to make a highpass filter the

easy way.easy way.

1.1. Change the sign of each sample in Change the sign of each sample in the filter kernel.the filter kernel.

2.2. Add 1 to the sample at the center of Add 1 to the sample at the center of symmetry.symmetry.

Ex. lowpass box Ex. lowpass box highpass highpass

9/19/19/1

9/19/19/1

9/19/19/1

9/19/19/1

9/19/89/1

9/19/19/1

Page 37: Digital Filters

Lowpass Lowpass to to

highpasshighpass

Page 38: Digital Filters

Lowpass followed by highpass = Lowpass followed by highpass = bandpassbandpass

(more efficient implementation)

Page 39: Digital Filters

Bandreject (stopband) = lowpass + Bandreject (stopband) = lowpass + highpass (lowpass or highpass)highpass (lowpass or highpass)

(more efficient implementation)