Determining Delay with Cross Correlation

Click For Summary

Discussion Overview

The discussion revolves around using cross-correlation to determine the time delay between a transmitted radar pulse and a received radar pulse, specifically in the context of a homework problem involving signal processing. Participants explore the implementation of cross-correlation in MATLAB, the generation of signals, and the interpretation of results.

Discussion Character

  • Homework-related
  • Mathematical reasoning
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant explains that cross-correlation can be used to determine the correlation between two signals and suggests that the resulting graph can indicate delays.
  • Another participant questions their understanding of how the cross-correlation function in MATLAB works, indicating potential confusion about the output.
  • One participant observes that the graphs of the transmitted and received signals show no delay and suggests redefining the signals to reflect the intended delay.
  • Another participant agrees that the initial definition of the received signal y is incorrect and suggests that the delay should be applied to the index of x rather than its amplitude.
  • Some participants propose modifications to the code to correctly implement the delay, but there is uncertainty about the correct approach and the implications of the changes.
  • There is a discussion about the correct interpretation of the problem statement regarding the placement of zeros in the signal definitions.
  • One participant expresses frustration over not seeing the expected delay in the results and questions the validity of their signal definitions.

Areas of Agreement / Disagreement

Participants generally agree that the initial definitions of the signals are problematic and that the implementation of the delay needs to be corrected. However, there is no consensus on the best approach to achieve this, and multiple competing views on how to define the signals remain unresolved.

Contextual Notes

There are limitations in the participants' understanding of how to apply the delay correctly in the signal definitions, as well as confusion regarding the output of the cross-correlation function in MATLAB. The discussion reflects ongoing attempts to clarify these issues without reaching a definitive solution.

Who May Find This Useful

This discussion may be useful for students and practitioners in signal processing, particularly those interested in radar signal analysis and the application of cross-correlation techniques in MATLAB.

Evo8
Messages
168
Reaction score
0

Homework Statement


Let x(t) be a transmitted radar pulse. The received radar pulse is y(t).

y(t)=ax(t-t_{d})+v(t)

Where v(t) is the additive noise and td is the time delay. The signals x(t) and y(t) are sampled and processed digitally to determine the delay

The discrete time signals are:
x(n) = x(nT)
y(n) = ax(n − D) + v(n)

where v(n) is the noise in the received signal, T is the sampling time of the
receiver, and D is the number of samples the received pulse is delayed by
the round trip to the target.

1. Explain how we can use cross correlation to determine the delay

2.Let x(n) be the 13-point Barker sequence
x(n) = [11111 − 1 − 111 − 11 − 11]

and let v(n) be a Gaussian zero mean sequence with variance σ^{2} = .01
A Gaussian random variable array with σ2 = 1 can be generated using randn(m,n). To convert the sequence to another value of σ2, just multiply the entire sequence by σ. Write a program that generates the sequence y(n), for 0 ≤ n ≤ 199 for variable parameters a and D. Choose D to be the last two digits of your birth year + the day of your birth. If your birthday was August 21, 1989, D = 89 + 21 = 110. Thus, in y(n), there will be D zeros prior to the beginning of the Barker sequence and enough zeros afterwards to increase the length of y(n) to 200.

D=94
a=0.8814

3. Plot the signals x(n) and y(n) for 0≤n≤199

4. Compute and plot the cross correlation. 0≤l≤185. Estimate the delay from the plot

Homework Equations


See code below.


The Attempt at a Solution



For #1 this is what I think. -The cross correlation can be used to determine the degree that two series are related or correlated. When the two signals are calculated and cross correlated the result can be graphed and analyzed for the delay. The bounds that the cross correlation is calculated to will indicate how much correlation at certain delays. If an area of interest is at the positive bound this shows a high correlation, if at the lower bound this indicated no correlation. If below the lower bound this can indicate a negative correlation.

Ok so I thought I had this one down but my results just don't match up to my original delay of 94. I get almost exactly double my original delay. Am I missing something here?

#3
Here is my code:
clear all
n=0:199;
a=0.8814;
D=94;
v=randn(1,200)*.01;
x=[zeros(1,94) 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13+D))];
y=a*x+v;
subplot(2,1,1); plot(x); grid
xlabel('...'); ylabel('...');
title('x(n) Plot');
subplot(2,1,2); plot(y); grid
xlabel('...'); ylabel('...');
title('y(n) Plot');

The plots from this code
attachment.php?attachmentid=43063&stc=1&thumb=1&d=1327368831.jpg



For #4 I reused the code and added the cross correlation:

clear all
n=0:185;
a=0.8814;
D=94;
v=randn(1,200)*.01;
x=[zeros(1,94) 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13+D))];
y=a*x+v;
z=xcorr(x,y);
subplot(1,1,1); plot(z); grid
xlabel('Delay'); ylabel('Amplitude');
title('Cross Correlation');

The plot of my calculated cross correlation
attachment.php?attachmentid=43064&stc=1&thumb=1&d=1327368831.jpg


From looking at this plot of the cross correlation I would say the delay is at 200. The delay I used in the data was 94 though? Where am I going wrong?

Thanks for any help on this and sorry for the super long post.
 

Attachments

  • Lab5_3.jpg
    Lab5_3.jpg
    23.9 KB · Views: 969
  • Lab5_4.jpg
    Lab5_4.jpg
    27.1 KB · Views: 1,344
Physics news on Phys.org
Ive looked over the code again and I have a feeling I am on the right track. Maybe I am just not understanding how the cross correlation in MATLAB works?

Im using the function xcorr

does anyone have experience using this function?
 
Hey Evo8! :smile:

If you look at you graphs of x and y, you can see that there is no delay.
The vector y only has a little noise.

You should define x without the delay zeroes in front, and y with the delay zeroes.

Now, your cross correlation gives you a peak at 200.
Since your vector is 200 entries long, this corresponds to a delay of 0, which is what you have now (it wraps around).
 
Hi ILS!

I did notice that there is no delay. However I don't think defining my x without the delay zeros in front is the correct approach. The x is supposed to be a 200 elements array with the barker sequence given D zeros (94 in my case) in and then enough zeros after to complete the 200 element.

However I am looking at it again now and I think I see a problem with my y definition. In the problem statement it is defined as follows y(n) = ax(n − D) + v(n). I didnt seem to include that -D in my y definition.

I changed my code to the following: (See changes in bold)

clear all
n=0:185;
a=0.8814;
D=94;
v=randn(1,200)*(.01)^2;
x=[zeros(1,94) 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13+D))];
y=a*(x-D)+v;
z=xcorr(x,y);
subplot(1,1,1); plot(z); grid
xlabel('Delay'); ylabel('Amplitude');
title('Cross Correlation');


See the associated plot here:
attachment.php?attachmentid=43093&stc=1&d=1327455259.jpg


No you can see that I've placed a data cursor where the plot drops out. This happens to be right at 94 which is my delay. Does this look a little better? Why does it go back up at 300? I also see a very small spike at 200. This is where my array ends I assume?

For reference here are the input vs. output signals
attachment.php?attachmentid=43094&stc=1&d=1327455407.jpg


I feel like I am getting close but the data my not be as clean as it should be?

Thanks for your response
 

Attachments

  • Lab5_3a.jpg
    Lab5_3a.jpg
    29 KB · Views: 2,345
  • Lab5_3b.jpg
    Lab5_3b.jpg
    28.2 KB · Views: 2,373
x=[zeros(1,94) 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13+D))];
y=a*(x-D)+v;

I think your y is not quite right yet.
You have subtracted D from the amplitude of x (vertically) and not from the index of x (horizontally), which you can see in your graphs or x and y.

Perhaps you could try something like:
undelayed_x=[1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13))];
y=a*undelayed_x+v;
 
hmmm I am not sure this is quite right either though. First the delay D is not used at all in either x or y. So how could I see a delay of D if its not used? This is what I get for plots if I use this code:

clear all
n=0:185;
a=0.8814;
D=94;
v=randn(1,200)*.01;
x=[1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13))];
y=a*x+v;
z=xcorr(x,y);
subplot(1,1,1); plot(z); grid
xlabel('Delay'); ylabel('Amplitude');
title('Cross Correlation');

attachment.php?attachmentid=43097&stc=1&d=1327456772.jpg


attachment.php?attachmentid=43096&stc=1&d=1327456610.jpg


Also I am quite confident that my X is correct. My y however I believe is my issue.

See this text taken from the problem statement
Choose D to be the last two digits of your birth year + the day of your birth. If your birthday was August 21, 1989, D = 89 + 21 = 110. Thus, in y(n), there will be D zeros prior to the beginning of the Barker sequence and enough zeros afterwards to increase the length of y(n) to 200.

This one is stumping me. I am not sure how to go about it. The closes I've come is the previous set of plots. But as you said I am affecting the amplitude not the correct delay?
 

Attachments

  • test.jpg
    test.jpg
    28.8 KB · Views: 2,238
  • test2.jpg
    test2.jpg
    28.9 KB · Views: 2,328
As you can see in the graph, y is still not shifted in time.

Perhaps you can try with:

x=[zeros(1,D) 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13+D))];
undelayed_x=[1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13))];
y=a*undelayed_x+v;
 
I could try this. However it is not different then what is tried in the above post.So my result will not change.

This is from your previous post:
Perhaps you could try something like:
undelayed_x=[1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13))];
y=a*undelayed_x+v;

This is from my code in the previous post:
x=[1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13))];
y=a*x+v;

And this is from the last post:
x=[zeros(1,D) 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13+D))];
undelayed_x=[1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13))];
y=a*undelayed_x+v;

The y definition has not changed and is still using the "undelayed_x." Did you mean to try plotting the delayed X vs the undleayed x in your post above? This might work however i don't think its what's intended. The received signal is y not x. I am not sure where to go on this one.
 
Reading your problem statement again, I must modify my statement, since the delay is the wrong way around.

It should be:

x=[1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13))];
delayed_x=[zeros(1,D) 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13+D))];
y=a*delayed_x+v;

Either way, your result will change, since your x and y will be shifted in time, as they are supposed to.

You should not do anything else with the "delayed_x".
I only introduced it to construct the proper y, which can also be done in other (and better) ways.
 
  • #10
Ok now i think i may see where you were going with this. I was a bit confused.

So this is what i have for code: Note this is only the parts of interest right now.


x=[1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13))];
delayed_x=[zeros(1,D) 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 zeros(1,200-(13+D))];
y=a*delayed_x+v;
z=xcorr(x,y);

The plots below are ordered as follows. Cross correlation on y and x. x and then delayed_x. Where i think i didnt really understand was that the y is using the delayed x, when computing the cross correlation I am using the non delayed x and the y which has the delayed x within. Now I get a time shift.

attachment.php?attachmentid=43117&stc=1&d=1327496185.jpg


The cross correlation shows a peak at 106. This is somewhat close to my delay of 94? How does this look now? where does this discrepancy come from? The nature of computing cross correlation?

Thanks for the help ILS
 

Attachments

  • test3.jpg
    test3.jpg
    21.5 KB · Views: 2,232
  • #11
Good! :)

The discrepancy is because the shift is counted as negative (it is y[t-D]).
Since your vector has length 200, it wraps around and 200-94=106.
 
  • #12
Ah this makes sense!

Thanks so much. I apologize for not understanding where you were going with this. The gears were turning but it took a little bit for them to get up to speed.

Thanks again!
 

Similar threads

Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K
Replies
2
Views
2K
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K