create an log likelihood ratio detector in matlab

A log-likelihood ratio detector (LLR) is a common tool in signal processing for detecting the presence of a known signal within a noisy observation. The basic idea is to compare the likelihood of the observation given that the signal is present versus the likelihood of the observation given that there is no signal. The logarithm of this ratio is then used as a decision statistic.

Here's some sample MATLAB code that implements an LLR detector for a simple binary signal:

main.m
% Generate a binary signal with known pattern
signal = [1 1 0 1 0 0 1 0 1 0 0 1];

% Generate a noisy observation of the signal
noise = 0.5*randn(1,length(signal));
observation = signal + noise;

% Calculate likelihoods for signal present and signal absent cases
sigPresent = normpdf(observation,signal,1); % assuming unit variance
sigAbsent = normpdf(observation,zeros(size(observation)),1); % Gaussian noise with mean 0

% Calculate log-likelihood ratio
LLR = log(sigPresent./sigAbsent);

% Plot results
subplot(3,1,1); plot(signal,'o-'); axis([0 length(signal) -0.5 1.5]);
title('Signal');
subplot(3,1,2); plot(observation,'o-'); axis([0 length(signal) -4 4]);
title('Observation');
subplot(3,1,3); plot(LLR,'o-'); axis([0 length(signal) -8 8]);
title('Log-Likelihood Ratio');
780 chars
22 lines

This code generates a binary signal with alternating 1's and 0's and adds Gaussian noise with mean 0 and unit variance. It then calculates the likelihoods for the cases when the signal is present and when it is absent using the normpdf function from the Statistics and Machine Learning Toolbox. The log-likelihood ratio is computed and plotted along with the original signal and the noisy observation.

Note that in practice, the LLR detector may require tuning of its parameters, such as the variance of the noise or the threshold for making a binary decision. Additionally, more sophisticated LLR detectors may be needed for more complex signals and noise models.

related categories

gistlibby LogSnag