Algorithm for 'coeff' scaling of xcorr?
Show older comments
I am cross-correlating some vectors using xcorr, and need to scale the cross-correlation values from 0 to 1. Conceptually xcorr lets you do that with the scaling option 'coeff', but it does not work if the vectors are of different length; the vectors with which I am working are, unfortunately, of different lengths.
I know that the documentation says that when the 'coeff' scaling is used, it "normalizes the sequence so the autocorrelations at zero lag are identically 1.0". Conceptually, I could just manually divide all of my cross-correlation values by the autocorrelation... except the problem is, when I look at vectors of the same length (to understand how the 'coeff' calculation is occurring), I don't know what is being used as the "autocorelation". It isn't the autocorrelation of either vector individually, and doesn't seem to be any obvious calculation therein. For a simplistic example that demonstrated the problem, if I have two vectors a and b:
a = [1,2,3]
b = [3,4,5]
The regular cross-correlation with xcorr, xcorr(a,b) gives:
5 14 26 18 9
And when I scale it with xcorr(a,b,'coeff'), I get:
0.1890 0.5292 0.9827 0.6803 0.3402
All of the numbers have been divided by approximately 26.46, and I have NO idea where that number came from. If I did, it might let me manually scale all of my cross-correlations to zero. Does anyone know what goes into the calculation?
As an aside, since I know that when vectors are of different length, xcorr pads them with zeros when normally cross-correlating, I thought that I might manually pad my vectors with zeros as needed, and then use xcorr's 'coeff' function. After doing this, however, I think that the zero padding affects the calculation...
So, in short, I need to cross-correlate vectors of different lengths and scale the cross-correlation values between 0 and 1. Any help would be awesome. Thanks.
Accepted Answer
More Answers (1)
Hi Mike, How to use 'coeff' if the two matrix (A,B) have the different size of length?
Categories
Find more on Correlation and Convolution in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!