How to calculate the circular correlation with 2 sequences/arrays in Matlab?
Show older comments
Hello,
Trying to use Matlab to calculate the circular correlation between x = [2 3];, and y = [4 1 -8]; Unfortunately cannot find appropriate function, such as CXCORR or CIRCORR?
Can calulate using matlab Linear Correlation, Linear Convolution, Circular Convolution as follows:
EDU>> x = [ 1 3 5 ];
EDU>> y = [-2 2 4 6 8];
EDU>> convolution = conv(x,y)
convolution =
-2 -4 0 28 46 54 40
EDU>> a = [1 2 4];
EDU>> b = [-3 2 5 7 9];
EDU>> correlation = xcorr(a,b)
correlation =
9.0000 25.0000 55.0000 40.0000 21.0000 2.0000 -12.0000 0.0000 0
EDU>>
EDU>> x = [ 1 3 5];
EDU>> y = [-2 2 4 6 8];
EDU>> CircularConvolution = cconv(x,y,5)
CircularConvolution =
52 36 0 28 46
Appreciate any help.
kind regards. V.
2 Comments
ankith sri
on 1 Mar 2021
To calculate circular correlation Lets consider a and b Flip b fliplr(b) And use cconv(a,b) Without giving the intervals, you will get the output for circular convolution
MEng - The more you learn the more you forget!
on 1 Mar 2021
Answers (1)
Honglei Chen
on 20 Jul 2015
You can use
ifft(fft(a,5).*conj(fft(b,5)))
or
cconv(a,b([1 end:-1:2]),5)
HTH
2 Comments
MEng - The more you learn the more you forget!
on 20 Jul 2015
Edited: MEng - The more you learn the more you forget!
on 20 Jul 2015
Honglei Chen
on 21 Jul 2015
For this set of a and b, 6 points is already linear convolution, so there is no need to go through cconv although you could. The main issue here is the convention used in your book, which seems to consider moving to the left as index 1. In most literature I believe the convention is opposite. That's why you see the mismatch. Try the following:
fliplr(fftshift(cconv(a,fliplr(b))))
or
fliplr(circshift(ifft(fft(a,6).*conj(fft(b,6))),-1,2))
Categories
Find more on Correlation and Convolution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!