Filter löschen
Filter löschen

correlation of signals

2 Ansichten (letzte 30 Tage)
Padma
Padma am 10 Nov. 2011
HI
I have used the following code to compute correlation:
[FileName,PathName] = uigetfile('mitsplit_00_(Left)[1]');
PathOriginal=sprintf('%s%s',PathName,FileName);
[xt,fs]=wavread(PathOriginal);
[FileName,PathName] = uigetfile('mitsplit_01_(Right)[1]');
PathOriginal1=sprintf('%s%s',PathName,FileName);
[yt,fs]=wavread(PathOriginal1);
fs=8000;
[c,lags]=xcorr(xt,yt)
the problem with this is it is printing so many values that i cannot find the maximum value and get the corresponding lag value.
I just started matlab recently. Please excuse me if my doubt is silly.
Thanks in advance

Antworten (2)

Wayne King
Wayne King am 10 Nov. 2011
Don't leave the semicolon off. And look for where the maximum occurs.
x = cos(pi/4*n);
y = cos(pi/4*n-(3*pi)/4);
[c,lags] = xcorr(y,x,'coeff');
[maxcorr,I] = max(c);
fprintf('The maximum occurs at lag %d\n', lags(I))
  2 Kommentare
Padma
Padma am 10 Nov. 2011
[c,lags] = xcorr(y,x,'coeff');
[maxcorr,I] = max(c);
could you please explain why we are using 'coeff' here and the next line also in more detail
Honglei Chen
Honglei Chen am 10 Nov. 2011
You don't have to use 'coeff'. It is just a normalization. The next line is getting both maximum value and the index where that value happens. I think this is not the first time you ask about these lines so I would strongly suggest you to read the documentation for both xcorr and max, try out the examples and see the result. It is actually quite obvious if you put your hand on it.

Melden Sie sich an, um zu kommentieren.


Wayne King
Wayne King am 10 Nov. 2011
You may also want to read over my examples in this thread:

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by