Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Corelation problem in matlab.

Status
Not open for further replies.

syedshan

Advanced Member level 1
Advanced Member level 1
Joined
Feb 27, 2012
Messages
463
Helped
27
Reputation
54
Reaction score
26
Trophy points
1,308
Location
Jeonju, South Korea
Visit site
Activity points
5,134
Dear all,

I am was not convinced or may be could not understand the correlation in matlab i.e. xcorr function.
So to test I simple made two exactly similar sine wave without any delay, and it gives me delay of 21.
I cannot understand why. please first see the code below

Code:
fo=200; fs=2500;
t=0:1/fs:.008;
x=sin(2*pi*fo*t);
y=x; %now x and y are exactly the same

%correlation start here
xc = xcorr(x,y);
[a,delay]=max(xc);
subplot(3,1,1); plot(t,x); %xlabel(t);
subplot(3,1,2); plot(t,y);
subplot(3,1,3); plot(xc);

display(sprintf('maximum of xc  is %d',max(xc)));
display(sprintf('delay is %d',delay));

So I get the delay at the index 21, where I think we should not have any delay. Note that the x and y both have 21 elements.
What I understand is, may be matlab implicitly padd zeros to the second element, in this case y,

Also the please clarify one more thing that the maximim value in the vector 'xc' indicates that at this point the peaks of the two points come together right...!


Thanks in advance,
Shan
 

You can use correlation to compare the similarity of two sets of data. Correlation computes a measure of similarity of two input signals as they are shifted by one another. The correlation result reaches a maximum at the time when the two signals match best. If the two signals are identical, this maximum is reached at t = 0 (no delay). If the two signals have similar shapes but one is delayed in time and possibly has noise added to it then correlation is a good method to measure that delay.

small modification in the code might help you

[xc,lag] = xcorr(x,'coeff');
[a,delay]=max(xc);
subplot(3,1,1); plot(t,x); %xlabel(t);
subplot(3,1,2); plot(t,y);
subplot(3,1,3); plot(lag,xc);
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top