# Algorithms for detecting the difference between two signals

If I have two signals $$X$$ and $$Y$$, where $$X$$ is a clean signal and $$Y$$ is the same signal with linear white Gaussian noise and an amplitudes of $$10^{-4}$$. How could one use an algorithm to detect if there are similarities between the signals.

I have currently come across cross correlation, which I am still trying to understand but are there any other methods that could be use, the idea is that I would be able to code it in matlab, so no tool boxes can be used. Could there be a matrix approach where you read the signal into a matrix form and decompose the noise and amplitudes from the matrix to get back to the original signal

This is currently a project I am doing for one of my course, so I am not looking for someone to give a answer, I am looking for advice and where I should be look, maybe relevant documentation.

The two samples are 16-bit and sampled at 44.1Khz

My apologise I have just been informed that the Y signal was renormalized after the Gaussian white noise and amplitude modulation.

• Do you know $X$ in advance, or you need to extract $X$ from $Y$ by comparing it to a pre-defined set of signals? – BlackMath Feb 9 at 20:37
• We have been given X in advance, so we need to see if the X signal can be found in Y. So the basic idea is to form an algorithm to eventually be used if given a signal X' and another signal Y' and use the algorithm to identify if the X' signal lies in Y'. Obviously in a real world application we would not know the noise or if the signal was clipped ect. But at the moment we know that the X signal lie in the Y we just need to find away to extract that information. – james2018 Feb 9 at 20:45
• If you know $X$ in advance, you don't need to see if $X$ lies in $Y$, because you know it lies in it. A more realistic application is you don't know $X$ (not the noise, because noise is always unknown), and then find $X$ from a pre-defined set of signals that closely resembles $Y$. This is a detection problem. You can use the maximum likelihood function, which reduces to Euclidean distance between the $X$ and $Y$, which is further reduced to correlation. – BlackMath Feb 9 at 20:54

This is a pretty common problem, and you’ll see it all the time in radar/sonar/___ar processing. Cross-correlation is really the thing you’d want to use here in my opinion.

In layman’s terms, you can use cross-correlation to do “template matching”. In radar applications, were looking for the signal we sent out to return to us. Since we know what signal we sent out, we can use that as a template and use cross-correlation as a mathematical tool to “search” for that template signal in the received signal.

So in your problem statement, you have the signal X which and the signal Y. It seems that Y = X + N, where N is some noise signal. To use cross correlation in MATLAB, you can simply just do [xc, lags]=xcorr(Y, X). Now ideally, the peak of the magnitude of xc will tell you precisely where the signal X “starts” in your signal Y. It’s important to note that the output of the MATLAB xcorr function will include “negative” time lags, so when you plot it, use plot(lags, abs(xc)).

If you plotted the magnitude of xc, that is abs(xc), you’ll likely notice a discernible peak above all of the noise. This would tell you that indeed, the signal X is present in the signal Y.

Now that’s just a simple overview of cross-correlation; naturally there are a lot of fine details, but hopefully that should get you started!

Implementation note for cross-correlation: If you wanted to do circular cross-correlation or not use any built ins, you could do it with discrete Fourier transforms (DFT/FFT): xc = IFFT( FFT(Y) .* conj(FFT(X)) ). If you’d like to learn more about the mathematics of this, check out Wikipedia and the convolution theorem.

If the only thing you know for sure is that the noise is white gaussian, you can substract two signals of your in order to obtain the noise. Then you can find the mean and variance. Use this information and design a filter (i.e. AR process). Then you have your noise creator. Now you can obtain pseudo-observations with noise and use these observations to obtain an estimator. Finally, you can play around with your error to show reducing nature with increasing number of observations etc.