Effacer les filtres
Effacer les filtres

correlation of signals

2 vues (au cours des 30 derniers jours)
Padma
Padma le 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

Réponses (2)

Wayne King
Wayne King le 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 commentaires
Padma
Padma le 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 le 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.

Connectez-vous pour commenter.


Wayne King
Wayne King le 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