Sunday, November 08, 2009

Matlab: Convolution Operation in Matched Filter

A script to test matched filter design for a given waveform.
In this example, the input signal is in below:





clc;
clear;
%Matched filter is actually a convolution operation between input signal and matched filter with %impulse response h(t)=s(T-t) %s(T-t) ->input signal is flipped over at t=0 and shift to the right by T %seconds %where T is the period of the input signal %(Doing MF in discrete form rather than in %continous form because it is easier to compute)

%Case I
s1=[2 1 ] %input signal to matched filter (each unit in the matrix is assumed to be 1s)
h1=[1 2 ] %impulse response of the matched filter h(t)=s(T-t), where T=2 in this case
output1=conv(s1,h1)

% If higher resolution is needed, let's say 0.5s, just double the sampling
%frequency, hence the matrix size is doubled.


%Case II
s2 = [2 2 1 1 ] % (each unit in the matrix is assumed to be 0.5s)
h2 = [1 1 2 2 ]
output2=conv(s2,h2) % The output value is also doubled then the exact value!! So it is incorrect!
output2=0.5*conv(s2,h2) % Therefore the convolution needs to be multiplied with sampling time, 0.5s

%Case II %In 0.25s resolution
s3 = [ 2 2 2 2 1 1 1 1]
h3 = [ 1 1 1 1 2 2 2 2]
output3=0.25*conv(s3,h3)

%The 3 cases above are consistent where at T=1s, output=2 & T=2s, output=5 %If keep on increasing the %sampling frequency or finer resolution, output approaches to continuous form

---------------------------------------------
Work Screen
---------------------------------------------

s1 =

2 1


h1 =

1 2


output1 =

2 5 2


s2 =

2 2 1 1


h2 =

1 1 2 2


output2 =

2 4 7 10 7 4 2


output2 =

1.0000 2.0000 3.5000 5.0000 3.5000 2.0000 1.0000


s3 =

2 2 2 2 1 1 1 1


h3 =

1 1 1 1 2 2 2 2


output3 =

Columns 1 through 11

0.5000 1.0000 1.5000 2.0000 2.7500 3.5000 4.2500 5.0000 4.2500 3.5000 2.7500

Columns 12 through 15

2.0000 1.5000 1.0000 0.5000

The 3 cases above are consistent where at T=1s, output=2 (purple colur) & T=2s, output=5 (red color)

No comments: