# Using MATLAB xcorr() to Find a Signal Hidden Behind Noise

I am trying to develop some code to find a transient signal in a data set I have. Before I get there however I am trying to write code using simulated data.

I first am creating a signal with a specified frequency and then adding white noise to it.

I then iterate through a loop where I create a reference signal at an incremental frequency. I take the FFT of both signals and the I xcorr the results.

With this methodology I get descent results when I use a SnR ratio of greater than -15 dB, but after that my results are no good. Is there anyway I can optimize this to find signals that are hidden deeper than -15 dB SnR?

My Code:

t = linspace(0,16*pi,1000);
y = cos(2*t);
z = awgn(y,-10);
fftz = fft(z);

subplot(2,1,1);
plot(t,z)
subplot(2,1,2);
plot(t,y)

freq = linspace(0.1,10,500);

for i=1:500
reference_signal = cos(freq(i)*t);
fftr = fft(reference_signal);
Q(i) = max(abs(xcorr(fftz,fftr)));
end

subplot(3,1,1);
plot(t,y)
subplot(3,1,2);
plot(t,z)
subplot(3,1,3);
plot(freq,Q)

The output

• Try to look into cross-ambiguity fuction. – learner Jun 19 '14 at 17:21
• Is there anything missing in my answer? If not, could you please mark it? – Royi Jul 31 at 13:23

You're basically doing a bank of hypothesis to find your signal using Matched Filter.

Though you use a slightly different method.

First of all, you should leave the signal in the time domain and calculate the cross correlation or their multiplication at the frequency domain. Yet, since your signal doesn't have unknown phase (Or delay) multiplication will do (It covers the cross correlation at time zero) -> which is equivalent of what you do at the frequency domain.

Since you're using AWGN the performance depends on the Effective SNR.
The effective SNR is a function of the energy of the signal, variance of the noise and the number of samples.

If you set the signal and the variance of the noise, just use more samples (Of the Signal -> Equivalent of faster sampling rate).

Your method actually does work even with -30 dB SNR if you feed it 100k data points (I've checked).

Also I don't see the point of using the first instead of the second: