corrcoef mistakenly gives 1 for different amplitude waveforms
2 views (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
the cyclist
on 4 Nov 2012
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
0 Comments
More Answers (1)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!