DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK...

56
DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK [email protected] http://www.dcs.warwick.ac.uk/~feng/ dcsp.html

Transcript of DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK...

Page 1: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

DCSP-15: Matched Filter

Jianfeng Feng

Department of Computer Science Warwick Univ., UK

[email protected]

http://www.dcs.warwick.ac.uk/~feng/dcsp.html

Page 2: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Filters

• Stop or allow to pass for certain signals

Page 3: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

There are four main classes of filter in widespread use:

filters. • The name are self-explanatory• This four types are shown in the next figure

Filter Types

• Lowpass

• highpass

• bandpass

• bandstop

Page 4: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Filter Types: TFs

Page 5: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

General Filter Design

• Using Chebyshev or Butterworth polynomials to approximate a square wave function in the frequency domain

• Any function can be approximated by a polynomials.

• Optimal filter design aims to minimize these ripples

• We are not discussing them here in details, but the principle is the same as our simple filter

Ideal case

Polynomial approximation

Page 6: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Filters

• Stop or allow to pass for certain signals

as we have talked before

• Detect certain signals such as radar etc

(pattern recognitions)

Page 7: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Ex: Detect it when it comes close

Page 8: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Matched filters: Question

Assume that we can detect

S = (s1, s2, s3, s4, s5 s6)

To find ai

y(0) = a0 x(0)+ a1 x(-1)+a2 x(- 2) + a3 x(-3) + a4 x(-4) +a5 x(-5)

so that we can find S, more precisely Y(0) = a0 s6 + a1 s5 + a2 s4 + a3 s3 + a4 s2 + a5 s1

Page 9: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

At time -5 we have x(-5) = S1=1 (length)

detector

Y(-5) = a0 1 + a1 x(-6) + a2 x(-7) + a3 x(-8) + a4 x(-9) + a5 x(-10)

Page 10: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

At time -4 we have x(-4) = S2= 2 (length)

detector

Y(-5) = a0 1 + a1 x(-6) + a2 x(-7) + a3 x(-8) + a4 x(-9) + a5 x(-10)

Y(-4) = a0 2 + a1 1 + a2 x(-6) + a3 x(-7) + a4 x(-8) + a5 x(-9)

Page 11: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

At time -3 we have x(-3) = S3= 3 (length)

detector

Y(-5) = a0 1 + a1 x(-6) + a2 x(-7) + a3 x(-8) + a4 x(-9) + a5 x(-10)

Y(-4) = a0 2 + a1 1 + a2 x(-6) + a3 x(-7) + a4 x(-8) + a5 x(-9)

Y(-3) = a0 3 + a1 2 + a2 1 + a3 x(-4) + a4 x(-5) + a5 x(-6)

Page 12: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

At time -2 we have x(-2) = S4= 4 (length)

detector

Page 13: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

At time -1 we have x(-1) = S5= 8 (length)

detector

Page 14: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

At time 0 we have x(0) = S6= 6 (length)

detector

Page 15: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Signal

• The input signal is

S = (s1, s2, s3, s4, s5, s6)

= ( 1, 2, 3, 4, 8, 6)

Page 16: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Matched filters: Question

To find ai

y(0) = a0 6 + a1 8 +a2 4

+a3 3 + a4 2 +a5 1

to detect that S = (s1, s2, s3, s4, s5 s6) is here

Page 17: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Matched filters: visulization

a0 x(0) + a1 x(-1) + a2 x(- 2) + a3 x(-3) + a4 x(-4) + a5 x(-5) = y(0)

Matched Matched !!!!

incoming signals

is matched

by the coefficients

a5

Page 18: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Data requirement

Without loss of generality, we can assume that

(normalized signals)

and we can assume that (normalized coefficients)

Page 19: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Remember that

If and only if ai = sN-I for all I which essentially says that the coefficients

a

and the incoming signal

s

are identical (matched, ai = sN-i).

Or equivalently

a0 SN + a1 SN-1 + …. + aN-1 S1 = 1

if and only if ai = sN-I for all i

a0 SN + a1 SN-1 + …. + aN-1 S1 < 1

otherwise

Ideas

Page 20: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

• Define ai = sN-i (reversing the order)

y(n) = a0 x(n) + a1 x(n-1) + … + aN x(n-N)

So when the signal arrives we have

y(n) = SN x(n) + SN-1 x(n-1) + … + S1 x(n-N)

= SN SN + SN-1 SN-1 + … + S1 S1

Matched filter

Page 21: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

At time -5 we have y(-5) =0.0877* 0.5262=0.0461

Y(-5) = a0 x(-5)+a1x(-6)+…

0.5262 0.0877 0.7016 0

detector

S= (0.0877 0.1754 0.2631 0.3508 0.7016 0.5262)

a = (0.5262 0.7016 0.3508 0.2631 0.1754 0.0877) x=( s1 0 0 0 0 0 )

Page 22: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Y(-4) = a0 x(-4)+a1x(-5)+a2x(-6)+…=0.1538

0.5262 0.1754 0.7016 0.0877 0.2631 0

detector

S= (0.0877 0.1754 0.2631 0.3508 0.7016 0.5262)

a = (0.5262 0.7016 0.3508 0.2631 0.1754 0.0877) s2 s1 0 0 0 0

Page 23: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

At time -3 we have Y(-3) = a0 x(-3)+a1x(-4)+a2x(-5)+a3x(-6)…=.2923

0.5262 0.2631 0.7016 0.1754 0.3508 0.0877 0.2631 0

detector

S= (0.0877 0.1754 0.2631 0.3508 0.7016 0.5262)

a = (0.5262 0.7016 0.3508 0.2631 0.1754 0.0877) s3 s2 s1 0 0 0

Page 24: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

At time -2 we have Y(-2) = a0 x(-2) +a1x(-3) +a2x(-4) +a3x(-5)+a4x(-6)…=

0.5262 0.3508 0.7016 0.2631 0.3508 0.1754 0.2631 0.3508

detector

S= (0.0877 0.1754 0.2631 0.3508 0.7016 0.5262)

a = (0.5262 0.7016 0.3508 0.2631 0.1754 0.0877) s4 s3 s2 s1 0 0

Page 25: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

At time -1 we have y(-1) = a0 x(-1)+a1x(-2)+a2x(-3)+a3x(-4)+a4x(-5)…

detector

S= (0.0877 0.1754 0.2631 0.3508 0.7016 0.5262)

a = (0.5262 0.7016 0.3508 0.2631 0.1754 0.0877) s5 s4 s3 s2 s1 0

Page 26: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

detector

S= (0.0877 0.1754 0.2631 0.3508 0.7016 0.5262)

a = (0.5262 0.7016 0.3508 0.2631 0.1754 0.0877) s6 s5 s4 s3 s2 s1

At time 0 we have Y(0) = a0 x(0) + a1 x(-1) + a2 x(-2) + a3 x(-3) + a4 x(-4) + a5 x(-5) + a6 x(-6) = 1

Page 27: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

detector

S= (0.0877 0.1754 0.2631 0.3508 0.7016 0.5262)

a = (0.5262 0.7016 0.3508 0.2631 0.1754 0.0877) 0 s6 s5 s4 s3 s2 s1

At time 1 we have y(1) = a0 x(1) + a1 x(0) + a2 x(-1) + a3 x(-2) + a4 x(-3) + a5 x(-4) + a6 x(-5) = 0.7961

Page 28: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Matched FilterOutcome

Page 29: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Matlab Demo

• Matched-filter-demo

• It is a simple idea, but useful

• A bit theory first

Page 30: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Auto-correlation functionAuto-correlation Function

Page 31: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Detection theory

• A means to quantify the ability to discern between information-bearing patterns and noise

• Patterns: stimulus in human, signal in machines

• Noise: random patterns that distract from the information

Page 32: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Can it be useful?

Any signal here?

Page 33: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Filter output

Page 34: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Filter output s=rand(1,100);s=s/sqrt(s*s');a=s;k=100;N=100*k;sigma=0.2;x=randn(1,N)*sigma;signal=zeros(1,N);for i=3*N/k+1:N*4/k x(i)=a(i-3*N/k)+x(i); signal(i)=a(i-3*N/k);endfor i=1:N*(k-1)/k c(i)=x([i:i+N/k-1])*s';endfigure(1)plot(x);hold onplot(signal,'r');figure(2)plot(c)

Page 35: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Matched filter

• The result is amazing

• It depends on SNR

• We will not go into details, but you might be able to investigate it using Matlab

Page 36: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

RGB = imread(‘bush.png');

I = rgb2gray(RGB);

J = imnoise(I,'gaussian',0,0.005);

K = wiener2(J,[5 5]);

figure, imshow(J), figure, imshow(K)

Tomorrow

Page 37: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

DCSP-16: Wiener Filter and Kalman Filter*

Jianfeng Feng

Department of Computer Science Warwick Univ., UK

[email protected]

http://www.dcs.warwick.ac.uk/~feng/dcsp.html

Page 38: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Father of cybernetics

Norbert Wiener: Harvard awarded Wiener a PhD, when he was 17.

Page 39: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

The RGB format stores three color values, R, G and B, for each pixel.

RGB = imread(‘bush.png');

size(RGB)

ans =

1500 1200 3

imshow(RGB)

Example

Page 40: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Example

Page 41: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

SetupRecorded signal x(n,m) = s(n,m) +(n,m)

for example, an image of 1500 X1200

True Signal noise

Page 42: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

RGB = imread(‘bush.png');

I = rgb2gray(RGB);

J = imnoise(I,'gaussian',0,0.005);

figure, imshow(I),

figure, imshow(J)

Setup

Page 43: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

To find a constant a(m,n) such that

E ( a(m,n) x(m,n) – s(m,n) ) 2

as small as possible

y(m,n) = a(m,n) x(m,n)

Different from the filter before, a(m,n) depends on (m,n) :

Adaptive filter

Setup

Page 44: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

2 2 2 2

2 2 2

( ) ( 2 )

2

E ax s E a x axs s

a Ex aExs Es

The quanttity above is minimized if the derivative of it with respect to a is zero

Setup

(optimal Wiener gain)

Page 45: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

• Without loss of generality, we assume that

Es=0 E=0

for simplicity of formulation .

• S, are independent

Setup

Page 46: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

The filtered output is given by

Note that the coefficient a depends on the position

is the local variance, E2 is the global variance (noise)

Algorithm

Page 47: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

where summation is over an area of N and M

1 2

1 2

1 2,

2 2 21 2

,

1( , )

1( , )

n n

n n

x n nNM

x n nNM

3X 3 area

(N=3, M=3)

Algorithm

Page 48: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Algorithm in Matlab

• wiener2 lowpass - filters an intensity image that has been degraded by constant power additive noise.

• wiener2 uses a pixelwise adaptive Wiener method based on statistics estimated from a local neighborhood of each pixel.

Page 49: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

RGB = imread(‘bush.png');

I = rgb2gray(RGB);

J = imnoise(I,'gaussian',0,0.005);

K = wiener2(J,[5 5]);

figure, imshow(J), figure, imshow(K)

Example

Page 50: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

• Large M and N reduce noise, but blur the photo• small M and N will not affect noise • optimal size should be used

Further issues

N=M=50 N=M=2

Page 51: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

•A more general version of Wiener: Kalman filter

•Kaman filter is widely used in many areas

(still a very hot research topic)

• As an introductory course, we only give you a taste of its flavour

Further issues

Page 52: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Kalman Filter: find out xk

• Have two variables state variable x which is not observable

xk = Fk xk-1 + Bkuk + wk

• Observable variable z which we can observe, but is contaminated by noise

zk = Hk xk +vk

where wk ~ N(0,Qk) and vk ~ N(0,Rk) are noise, Fk and Hk are constants.

Xk-1Input uk

Bk

Output xk

Page 53: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Kalman Filter For given xk-1|k-1 and pK-1|K-1

Predict•Predicted (a priori) state estimate xk|k-1 = Fk-1 xk-1|k-1+Bkuk

•Predicted (a priori) estimate covariance pk|k-1 = Fk-1 pk-1 |k-1 FK-1 +QK

Update•measurement residual yk = zk –Hk X k|k-1

•measurement residual covariance Sk = Hk Pk|k-1HK+Rk

•optimal Kalman gain Kk = P k|k-1 Hk (SK)-1

•updated (a posteriori) state estimate X k|k = x k|k-1 + Kk y k

•updated (a posteriori) estimate covariance pK|K = (I-K kH k) P k|k-1

Page 54: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Kalman Filter

• It is one of the most useful filters in the literature, as shown below

• We do not have time to go further, but do read around

clear allclose allN=1000;q=1;r=1;f=0.1;h=0.2;x(1)=0.5;xsignal(1)=0.5;xhat=zeros(1,N+1);phat=zeros(1,N+1);xhat(1)=x(1);phat(1)=x(1);p(1)=1;z(1)=0.1;y(1)=1;for i=1:Nxsignal(i+1)=f*xsignal(i)+randn(1,1)*sqrt(q)+1*cos(2*pi*0.01*i);z(i+1)=h*xsignal(i)+randn(1,1)*sqrt(r);endfor i=1:Nx(i+1)=f*xhat(i)+1*cos(2*pi*0.01*i);p(i+1)=f*phat(i)*f+q;y(i+1)=z(i+1)-h*x(i+1);s(i+1)=h*p(i+1)*h+r;k(i+1)=p(i+1)*h/s(i+1);atemp=x(i+1)+k*y(i+1);xhat(1,i+1)=atemp(1,i+1);atemp=(1-k*h)*p(i+1);phat(i+1)=atemp(1,i+1);clear atempendplot(xsignal);hold onplot(xhat,'r')plot(z,'g')plot(xhat,'r')

Page 55: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Applications• Attitude and Heading Reference Systems

• Autopilot

• Battery state of charge (SoC) estimation [1][2]

• Brain-computer interface

• Chaotic signals

• Tracking and Vertex Fitting of charged particles in Particle Detectors [35]

• Tracking of objects in computer vision

• Dynamic positioning

• Economics, in particular macroeconomics, time series, and econometrics

• Inertial guidance system

• Orbit Determination

• Power system state estimation

• Radar tracker

• Satellite navigation systems

• Seismology [3]

• Sensorless control of AC motor variable-frequency drives

• Simultaneous localization and mapping

• Speech enhancement

• Weather forecasting

• Navigation system

• 3D modeling

• Structural health monitoring

• Human sensorimotor processing[36]

Flight control unit of an Airbus A340

modern weather forecasting.

Page 56: DCSP-15: Matched Filter Jianfeng Feng Department of Computer Science Warwick Univ., UK Jianfeng.feng@warwick.ac.uk feng/dcsp.html.

Final slide

• Information theory

• FT (continuous, discrete, discrete +finite)

• Filters (band related filters, matched, Wiener + Kalman)

No lectures next week, but drop me a line if you need help for your assignment