Matched Filter Using Octave GNU Tool
1. Abbreviation
SNR – signal to noise ratio (S/N = Signal/Noise)
δ(t) – Dirac delta function: t=0 δ(0)= +∞; t≠0 δ(t)=0
PSK – Phase Shift Keying digital modulation
FSK – Frequency Shift Keying digital modulation
MLS – maximum length sequence
FIR – Finite Impulse Response
IIR – Infinite Impulse Response
2. Introduction
Matched filter is designed to recognize a signal of a known shape with additive noise. The algorithm does not reproduce the original signal form from the noise. If a sample signal is detected then the filter should react by increasing the output level (by maximizing the SNR ratio). In the ideal case the matched filter generates a pulse, and then the threshold device decides whether to receive the signal.
Matched filter is mainly used in radar and communication systems. More information about this can be found in [1], [2], [3].
Here I write without proof the basic information needed to implement the matched filter.

Matched filter has a finite impulse response and therefore is implemented digitally with FIR filter

The matched filter impulse response has:
where s(t) – signal sample, i.e. the signal that needs to be recognized by matched filter
Tsig – signal time lengthThus, the impulse response of the matched filter is a mirror image of the signal itself.
The correlation function is calculated at the filter output. This is easy to prove. Let the signal s(t) come to the filter input then calculating the convolution:
where
– correlation functionThe maximum output value of the filter is reached at time t = Ts and the value is proportional to the energy of the signal sample:

By calculating the Fourier transform of h(t), it is easy to show that the spectral characteristic of the matched filter has:
where
– complex conjugate of the signal sample spectrumIn the case of matched filtering, the frequency components of the signal are added coherently, and the frequency components of the noise are incoherent, which provides the maximum SNR.
It is important to choose the correct signal sample. I have already mentioned that the matched filter should generate a narrow pulse at the output after receiving the expected signal. Ideally the autocorrelation function of the signal sample should be Dirac delta function:
and take values:
R(τ) = 0 for τ ≠ 0
R(0) = +∞ for τ = 0 (6)
These conditions (5), (6) are in reality unreachable. Nevertheless it is possible to formulate the requirements for the signal. The signal shall be broadband or often said to be noiselike (pseudorandom) because white Gaussian noise has the same correlation function (5).
To evaluate the bandwidth, the concept of a signal base is introduced:
where Fband – signal band width, Tsig – signal duration
Matched filter signal shall satisfy the condition:
Here are some examples of the signals used for matched filter:

Barker code

Maximum length sequence (MLS)

Gold sequence

Kasami sequence

Walsh functions. These functions are orthogonal and are used to separate communication channels. Autocorrelation and crosscorrelation of these functions are not well suited for matched filter, but they are often used in communication systems
Next, I’ll give you some examples of matched filters.
3. Matched filter for chirp signal
Consider an example of matched filter for chirp signal:
where 0 ≤ t ≤ Tsig
See the Figure 31:
Figure 31: Chirp Signal
Then using (1) the Matched Filter Impulse Response has:
where 0 ≤ t ≤ Tsig
See the Figure 32:
Figure 32: Chirp Matched Filter Impulse Resonse
Now we send the signal (9) to the input of this filter and get the filter response, as shown in Figure 33. After receiving the chirp signal, the matched filter generates a short pulse. There are still lateral local maxima, the level of which is significantly lower than the main maximum.
Figure 33: Matched Filter Response on the Chirp Signal
4. Matched filter for Phase Shift Keying (PSK) with Barker Code
Consider a simple version of Phase Shift Keying (PSK) with only two phases 0 and π.
Note: Logical 0 can be defined as 1.
We use the Barker Code with a length of 11:
BarkerCode_11 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
This sequence has a good autocorrelation function with a narrow peak. See the Figure 41
Figure 41: Autocorrelation function of the Barker code with the length 11
Now let’s build a PSK with Barker code. See the Figure 42:
Figure 42: PSK with the Barker code with the length 11
Using (1) the matched filter pulse response has the form shown in Figure 43
Figure 43: Matched Filter Impulse Response of the PSK with the Barker code
Then the reaction of the matched filter to this PSK signal sample shown in the Figure is 44:
Figure 44: Matched Filter Response on the PSK with the Barker code
Note:
The PSK signal can be considered as a packet of radio pulses with phases 0 and π. Then we can build a matched filter for only one radio pulse and then use the tdelay time delay line for each subsequent radio pulse with a coefficient bi : +1 for the phase 0 and 1 for the phase π. See the Figure 45
Figure 45: PSK Matched Filter Using only One Radio Impulse S*one(jω)
where t_delay – one radio impulse time length
5. Matched filter for Maximum Length Sequence (MLS)
Maximum Length Sequence (MLS) is pseudorandom binary sequence which is generated using linear feedback shift registers. MLS has a periodic sequence with period N:
where k – bits number of the shift register
The shift register and its feedbacks can be determined using a polynomial. For example, the polynomial (13) corresponds to the shift register shown in Figure 51.
The polynomial can still be written as a binary number. In our example: 10000011, where bits: 7, 1, 0 have the values 1 (feedbacks are active) and all other bits have the values 0.
Figure 51: MLS: Feedback Shift Register
In the example, an MLS length is
and the register initial (start) value must be nonzero.
Now let’s build a Matched Filter for MLS using (1). The signal at the filter output after receiving the MLS is shown in Figure 52
Figure 52: Matched Filter Response on the MLS 10000011 sequence
Notes:

The lateral local maxima of the MLS autocorrelation function do not exceed the value:
In our example: 
There are many polynomials of different lengths that you can use to form the MLS sequence that suits you. The table of polynomials is easy to find in the special literature. See the few polynomials in the Table 51:
Table 51: MLS polynomials

MLS is also used for PSK or FSK modulation. In this case, you can also get an effective matched filter
6. Realization of the matched filter
Matched filter has a finite impulse response and therefore is implemented in digital technic using FIR filter. See the article: “FIR Filter Implementation Using Octave GNU Tool and C Language“
7. Download the matched_filter.m
Octave GNU file matched_filter.m
You can see in the file all calculations and all graphics for the article.
8. Literature / References
[1] John G. Proakis, Masoud Salehi, “Digital Communications”, Fifth Edition, MC GrawHill, Higher Education, ISBN 978–0–07–295716–7
[2] L.Rabiner, B.Gold “Theory and application of digital signal processing“, PrenticeHall, Ing Englewood Cliffs, New Jercy 1975
[3] Allan V. Oppenheim “Applications of Digital Signal Processing“, Massachusetts Institute of Technology Cambridge, Prentice Hall, Inc., Englewood Cliffs, New Jersey, 1978
[4] I. S. Gonorovsky “Radio engineering circuits and signals”, Moscow, “Radio and Communications”, 1986