Here's a MATLAB implementation of the cross-correlation algorithm using matrix multiplication:
main.m789 chars27 lines
To use this function, simply call myxcorr(x, y)
, where x
and y
are the two signals to compute the cross-correlation of. The function will return two outputs: xcorr
is the cross-correlation vector and lag
is the vector of lags in samples. The function will also plot the cross-correlation using stem
. Note that in order to make the cross-correlation symmetric around zero lag, we zero-pad the shorter signal to match the length of the longer signal.
gistlibby LogSnag