Cross-correlation without using xcorr (vectorized)

19 views (last 30 days)
Hello, I cannot use xcorr built-in function and I will correlate two discrete signals directly in my code. I have seen some answers pointing to some FileExchange submissions that go over a nested for-for loop to do the computations. This is maybe faster, I don't doubt, but I would like to do the computation with a single for. I am trying the following, where the plots show the comparison between my method with xcorr and with frequency-domain correlation. I see non-negligible differences with my code...by the way there seems to be a lag between the xcorr and frequency domain correlation.
b0 = [block0 zeros(1,bsize)];
b1 = flip([conj(blockWPC) zeros(1,bsize)]);
clear bf;
for k=1:(2*bsize)
bf(k) = sum(b0.*circshift(b1,k));
end
plot(abs(ifftshift(ifft(fft(block0,2*bsize).*conj(fft(blockWPC,2*bsize))))),'*-');hold on;
plot(abs(xcorr(block0,blockWPC)),'o-');
plot(abs(bf));

Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!