Matched Filter
Matched Filter
Initialization
clc
clear all
close all
noise = input('Do you want to add noise of normal distributed press y: ', 's');
sigma = 0.1;
• noise = input('Do you want to add noise of normal distributed press y: ', 's'): Prompts the user
to decide if they want to add noise to the signal. If the user enters 'y', noise will be added.
• sigma = 0.1: Sets the standard deviation (σ) for the normal distribution used to generate the
noise.
Unipolar NRZ
• kron(data, bit_duration): The Kronecker product is used to repeat each bit in the data vector
according to the bit_duration vector. For example, if data = [1 0 1] and bit_duration = [1 1 1],
the resulting uni_nrz would repeat each bit for the specified duration.
if noise == 'y'
uni_nrz = uni_nrz + (sigma .* randn(1, length(uni_nrz)));
end
• fliplr(bit_duration): Flips the bit_duration vector left-to-right. This is done to create a matched
filter impulse response.
• conv(...): Performs a convolution between the flipped bit_duration and the uni_nrz signal. The
convolution simulates the response of a matched filter, which is used to extract the data from
the noisy signal.
Polar NRZ
data_p = data * 2 - 1; % first convert the data into 1's and -1's
pol_nrz = kron(data_p, bit_duration);
• data_p = data * 2 - 1: Converts the binary data (0 and 1) into polar values (-1 and 1).
• kron(data_p, bit_duration): Similar to unipolar NRZ, the Kronecker product is used to repeat
each bit in the data_p vector according to bit_duration.
if noise == 'y'
pol_nrz = pol_nrz + (sigma .* randn(1, length(pol_nrz)));
end
• Similar to the unipolar NRZ section, this adds noise to the pol_nrz signal if the user chose to
add noise.
• Similar to the unipolar NRZ section, this performs a convolution of the flipped bit_duration
with the noisy pol_nrz signal to simulate the matched filter output for the polar NRZ
encoding.
• subplot(4, 1, 1): Divides the figure into a 4-row, 1-column grid of subplots and selects the
first subplot.
• plot(uni_nrz): Plots the unipolar NRZ signal.
• title('Unipolar NRZ'): Adds a title to the subplot.
subplot(4, 1, 2)
plot(mf_uni_out)
title('Matched Filter Output for Unipolar NRZ')
• Plots the matched filter output for the unipolar NRZ signal in the second subplot.
subplot(4, 1, 4)
plot(mf_pol_out)
title('Matched Filter Output for Polar NRZ')
• Plots the matched filter output for the polar NRZ signal in the fourth subplot.
Summary