Reply by Rune Allnor February 6, 20082008-02-06
On 5 Feb, 15:25, "matuser" <imol...@igepn.edu.ec> wrote:
> 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?
First, remember that each correlation coefficient is the inner product of two vectors: In matlab: N= length(y); % y is the shorter vector xx_k=x(n-k:n-k+N-1); Cxy(k) = xx_k*y; This inner product is proportional to the norm of xx_k and y: |Cxy(k)| = |xx_k|*|y|*cos( the angle between xx_k and y ) To normalize the correlation to the range [-1,1] you need to normalize by the norms: cxy(k) = Cxy(k)/(|xx_k|*|y|) So you basically need to apply this normalization to each element in the correlation series. Not particularly difficult, as long as you remember to update the new factor |xx_k| for each lag. Rune
Reply by Fred Marshall February 5, 20082008-02-05
"matuser" <imolina@igepn.edu.ec> wrote in message 
news:Ad6dnVX40Nty7DXanZ2dnUVZ_vmlnZ2d@giganews.com...
> 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 > &#2013265922;?ox&#2013265922;?&#2013266077; and &#2013265922;?oy&#2013265922;?&#2013266077;. 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 &#2013265922;?&#2013266086;. > > > PS/ Excuse me that I am posting again my question, but I can not see where > it was posted on the first time...
I would experiment to get what I wanted. Use synthetic sequences that have the characteristics you want but with no noise. In other words a perfect signal in each case. Then you should be able to generate the best correlation possible under the circumstances. Maybe call that 1.0 (or -1.0) or compute the correlation coefficient analytically (by picking a likely signal) with one of them padded with zeros - I think the choice is yours here. As above, there aren't many options if the sequences are different length. One would be to repeat the shorter one if the ratio of lengths is large. But, would that make sense in your situation? It's also tricky / fraught with problems. Not recommended unless you really know what you're doing. Another would be to pad zeros on the short one so it's the same length as the longer one. If you do the latter, then you'd be correlating the short one over shortened lengths of the long one. So, the assumption must be that the replica in the long one is not much longer or not longer than the short one. This is exactly what happens in a matched filter in radar or sonar. The short one is a replica of the transmit pulse and the long one is the entire receiver input over time. You should answer the question for yourself: Why is absolute correlation coefficient important? Compared to a peak unnormalized? Fred
Reply by matuser February 5, 20082008-02-05
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
&ldquo;x&rdquo; and &ldquo;y&rdquo;. 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 &hellip;.


PS/ Excuse me that I am posting again my question, but I can not see where
it was posted on the first time...