Presentation is loading. Please wait.

Presentation is loading. Please wait.

Digital Filters. What have we seen so far?  So far we have seen… Box filterBox filter  Moving average filter  Example of a lowpass passes low frequenciespasses.

Similar presentations


Presentation on theme: "Digital Filters. What have we seen so far?  So far we have seen… Box filterBox filter  Moving average filter  Example of a lowpass passes low frequenciespasses."— Presentation transcript:

1 Digital Filters

2 What have we seen so far?  So far we have seen… Box filterBox filter  Moving average filter  Example of a lowpass passes low frequenciespasses low frequencies  small, gradual changes in the signal are passed  higher frequencies are attenuated (reduced/removed/suppressed)

3 Applied by cross correlation (sum of products) of image f and mask h If mask is centered about origin, (x,y) in image: If origin, (x,y), in image is aligned with (0,0) in mask:

4 But how do we know what the application of an arbitrary mask actually does to the image?

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

6 Our moving average (box) filter Example of a lowpass filter (passes low frequencies, attenuates high frequencies) y[n] = 1/3 x[n-1] + 1/3 x[n] + 1/3 x[n+1] More generally y[n] = h[-1] x[n-1] + h[0] x[n] + h[1] x[n+1]

7

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

9 amplitude (loudness)

10 phase (time/space shift)

11 frequency (speed)

12

13 Lowpass filters Input: (before) 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: (after) y(t) = 0.5*sin(t) + sin(3*t+pi/3) y(t) = 0.5*sin(t) + sin(3*t+pi/3)

14

15 So how can we determine how our moving average filter behaves?  11 point and 51 point moving average filters (on the previous slide) obviously produce different outputs even when given the same input!  Answer: By determining how a particular filter responds to an impulse (their impulse response function).

16

17

18

19

20 So given …,h[-1],h[0],h[1],… how can we plot the impulse reponse. 1. Perform the z-transform (the discrete version of the Laplace transform) of h resulting H. 2. Plot H on the unit circle. The magnitude of H (abs(H) or |H|) is amplitude and the angle of H (arg(H)) is the phase.  Say we have a 3 point box filter: h[- 1]=h[0]=h[1]=1/3.

21 So given …,h[-1],h[0],h[1],… how can we plot the impulse response.  Say we have an 11 point box filter: 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.

22 Frequency response of 3 and 11 point box filters

23

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

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

26 3 point box filter vs. 3 point gaussian

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

28 How can we make these other filters?

29 Spectral inversion: How to make a highpass filter the easy way. 1. Change the sign of each sample in the filter kernel. 2. Add 1 to the sample at the center of symmetry. highpass  lowpass highpass  lowpass lowpass  highpass lowpass  highpass bandpass  bandreject (stopband) bandpass  bandreject (stopband) bandreject  bandpass bandreject  bandpass

30 Lowpass to highpass

31 Lowpass followed by highpass = bandpass

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

33 Application of filters Edge detection

34 Recall the first derivative test from calculus: Let the function f be continuous on some interval (c-,c+) containing the critical point c. 1.If f’(x)>0 for x in (c-,c) and f’(x) 0 for x in (c-,c) and f’(x)<0 for x in (c,c+), then f has a local maximum at c. 2.If f’(x) 0 for x in (c,c+), then f has a local minimum at c.

35 Can we calculate the first derivative of an image? Let h 1 =[-1, 1]. Then f’(x) = g(x) = f(x)h 1 (x) where  is cross correlation. So we can then search f’(x) for extrema where: 0 occurs0 occurs -a,+b occurs-a,+b occurs +a,-b occurs+a,-b occurs

36 Recall the following from calculus regarding the second derivative: Let f be continuous on [a,b] and at least twice differentiable on (a,b). If f’’(x)>0 on (a,b), then f is concave up on [a,b], while if f’’(x) 0 on (a,b), then f is concave up on [a,b], while if f’’(x)<0 on (a,b), then f is concave down on [a,b].

37 Recall the second derivative test from calculus: Let the function f be defined on an open interval containing the critical point c where f’(c)=0, and let f’’ be continuous on this interval. 1.If f’’(c)<0, then c is a local maximum point. 2.If f’’(c)>0, then c is a local minimum point. 3.If f’’(c)=0, then no conclusion is possible without further investigation.

38 Also recall: A point c is called an inflection point of f if: 1.f is continuous at c; 2.the graph of f has a tangent line (possibly vertical) at [c,f(c)]; 3.f is concave up on one side of c and concave down on the other side.

39 We can consider the inflection point to be the location of an edge!

40 Can we calculate the second derivative of an image? Let h 1 =[-1, 1]. Then f’(x) = f(x)h 1 (x) Then f’’(x) = f’(x)h 1 (x)  where  is cross correlation. So we can then search f’’(x) for edges where: 0 occurs0 occurs -a,+b occurs-a,+b occurs +a,-b occurs+a,-b occurs

41 Can we calculate the second derivative of an image? A better way … let h 2 =[1, -2, 1]. Then f’’(x) = f(x)h 2 (x) Much more computationally efficient. Where does h 2 come from? From [-1, 1]  [1, -1] which is h 1 * h 1 where * is convolution.

42 Applying masks to images Convolution: Discrete form:

43 Frequency response (dB) and phase of first derivative filter.

44 Frequency response (dB) of first and second derivative filters.


Download ppt "Digital Filters. What have we seen so far?  So far we have seen… Box filterBox filter  Moving average filter  Example of a lowpass passes low frequenciespasses."

Similar presentations


Ads by Google