Matlab\'s cross-correlation function xcorr(x,y,maxlags) has an option maxlag, which returns the cross-correlation sequence over the lag range
xcorr(x,y,maxlags)
maxlag
I would recommend looking at this file to determine how you would want to implement the correlation described here.