function [cov,cor,rcor] = correl( raster1, raster2, shift)
% Correl: make a correlogram from raster arrays
% raster: LxM raster matrix
% shift: range of time shift
% cov: normalized correlation
% cor: raw spike correlation
% rcor: rate correlation

[length,trials] = size( raster1);

% insert zeros
wave1 = [raster1;zeros(shift,trials)];
wave2 = [raster2;zeros(shift,trials)];

% stretch and correlate
cor = xcorr( wave1(:), wave2(:), shift)/trials;

rate1 = mean(raster1,2);
rate2 = mean(raster2,2);
rcor = xcorr( rate1, rate2, shift);

cov = cor - rcor;
% plot( [cov,scor,rcor])
