corrcoef mistakenly gives 1 for different amplitude waveforms

I'm trying to obtain the crosscorrelation between sets of oscillations for a lag of zero, here is the relevant part of my code:
yintsplit=(linspace(minimumsplit,maximumsplit,2048))'; y2intsplit=(linspace(minimumsplit,maximumsplit,2048))';
zintsplit = interp1(yisplit,zisplit,yintsplit,'spline'); z2intsplit = interp1(y2isplit,z2isplit,y2intsplit,'spline');
[absplit, lagssplit] = xcorr(zintsplit,z2intsplit, [], 'coeff'); zzsplit = absplit(find(lagssplit == 0));
or
absplit = corrcoeff((zintsplit,z2intsplit); zzsplit = absplit(1,2);
When I plot the two sets of oscillations, they are clearly different. They have the same period, but their amplitude is different. But both xcorr and corrcoef give me a cross-correlation of 1! I'm perplexed, I have no idea what the problem is... Can anyone help? Thanks!

 Accepted Answer

I did not try executing your code. But two oscillations that vary only by amplitude are perfectly correlated, as this simple example illustrates:
x = (0 : 0.1: pi)';
y1 = sin(x);
y2 = 2*sin(x);
corrcoef([y1,y2])
figure
subplot(3,1,1), plot(x,y1,'.')
set(gca,'YLim',[0 2.1])
subplot(3,1,2), plot(x,y2,'.')
set(gca,'YLim',[0 2.1])
subplot(3,1,3), plot(y1,y2,'.')
axis square

More Answers (1)

Thanks a lot, you're absolutely right.
I subsequently looked into it a bit more, and if anyone needs any more clarification, here it is:
The way normalisation is done by the 'coeff' option in xcorr or by the crosscoeff function is as:
A.B/|A|.|B|
So naturally, as the cyclist points out, if the amplitude is the same but the period different, the cross-correlation will be renormalised to one.
One could however use (and specify) a different renormalisation which would also give an indication of the amplitude difference, which would be
A.B / ((|A|+|B|)/2)
This would have the effect of giving a lower correlation if the two oscillatory forms do not have the same amplitude.

Asked:

S
S
on 2 Nov 2012

Community Treasure Hunt

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

Start Hunting!