Sign in

username:

password:



Not a member?

Search matlab



Search tips

Subscribe to matlab



matlab by Keywords

Atanh | Autocorrelation | Bandpass Filter | C++ | Conv | Database | Deconv | Excel | FFT | Filter | Filtering | FIR | Fourier Transfrom | FSK | Gaussian Noise | Haykin | IFFT | Image | Java | LFSR | LMS | LPC | MEX | OFDM | QPSK | Radix | Random | Sampling | Segmentation | Simulink | Visual Basic | Waveform | Wavelet

Sponsor

NEW! TMS320C6474: 3x the performance. 1/3 the cost. Three 1 GHz cores on 1 chip.

Discussion Groups

Discussion Groups | Matlab DSP | Cross Correlation of 2 vectors of different lengths

Technical discussion about Matlab and issues related to Digital Signal Processing.

  

Post a new Thread

Cross Correlation of 2 vectors of different lengths - imol...@igepn.edu.ec - Feb 5 8:34:23 2008



Dear all,

My purpose is to determine if there is a correlation between two signals. I need to find if
they are correlated with a positive correlation close to 1 or an opposite one close to -1.

How do I normalize the cross-correlation coefficient when the 2 signals have different lengths?


I would like to perform a cross correlation of two finite length sequences “x” and “y”.
Length of x and y are different. I made the following script in order to determine the maximum
coefficient of correlation and the position of the lag.

x=[1 0 1 0 2 0 2 0];
y=-[1 0 1 0 2 0 2 0 2]; 
[corr,lag]=xcorr(x,y,'none');
[maximo,index] = max(corr); 
[minimo,index2] = min(corr);
if abs(maximo)<abs(minimo);
    max_corr=minimo;         %Value of maximum correlation
    lag_corr=lag(index2);    %Corresponding lag of maximum correlation    
else 
    max_corr=maximo; 
    lag_corr=lag(index); 
end
    
subplot(3,1,1),plot(x,'-o'),ylabel('amplitude'),xlabel('time),
subplot(3,1,2),plot(y,'-o'),ylabel('amplitude'),xlabel('time');
subplot(3,1,3),plot(lag,corr,'-o'),hold on, plot(lag_corr,max_corr,'ro'),ylabel('correlation
without normalization'),xlabel('lag');

In fact, this script gives the maximum correlation coefficient and its corresponding lag:

max_corr =

   -11
lag_corr =

    -2

What does mean this max_corr here? How do I normalize the correlation coefficients? If I use
the option:
[corr,lag]=xcorr(x,y,'coeff'), it gives me the correlation coefficients normalized, but this
option is just for vectors with the same length and this is not my case.

I would greatly appreciate some help and advice ….
C.



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: Cross Correlation of 2 vectors of different lengths - el01...@mail.ntua.gr - Feb 26 15:53:47 2008


Dear all,
>
>My purpose is to determine if there is a correlation between two signals. I need to find if
they are correlated with a positive correlation close to 1 or an opposite one close to -1.
>
>How do I normalize the cross-correlation coefficient when the 2 signals have different
lengths? 
>
>I would like to perform a cross correlation of two finite length sequences “x” and
“y”. Length of x and y are different. I made the following script in order to determine the
maximum coefficient of correlation and the position of the lag.
>
>x=[1 0 1 0 2 0 2 0];
>y=-[1 0 1 0 2 0 2 0 2]; 
>[corr,lag]=xcorr(x,y,'none');
>[maximo,index] = max(corr); 
>[minimo,index2] = min(corr);
>if abs(maximo) 
***************************************************
Hello,

one idea is the following:

1)Let the two vectors be x and y and without loss of generality let 
length(x)<length(y). Extend periodically x until it's length equals the length of y, namely
length(x_extended)==length(y).

2)run the command 
cross = xcorr(x_extended,y,'coeff');

and you have an approximation of the cross-correlation between x and y

Manolis C. Tsakiris



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )