%filters data and plots power spectrum for 64 electrode array
%requires raw data and sampling frequency

function [data, t] = PlotCrossCorr6( wave, time);

%extra=[0];
rev=fliplr(time);
t=cat(2,-rev,time);
t=t';
%waveFilt = BudapestbandPass(wave,1000,5,200);
waveFilt = BudapestbandPass(wave(:,2:65),1000,10,40,1000);
[waveCorr,lags] = xcov(waveFilt(200:700,1:64),200,'coeff');
%[waveCorr,lags] = xcorr(waveFilt(1:100,2:65),200,'coeff');

%Lrotate=ones(8,8);
%for m=1:8
 %   for n=1:8
  %      Lrotate(m,n)=n*8-m+1;
  % end
  %end
%Lrotate=reshape(Lrotate,1,64);

%Rrotate=ones(8,8);
%for n=1:8
 %   for m=1:8
  %      Rrotate(m,n)=8*(8-m)+n;
  % end
  %end
%Rrotate=reshape(Rrotate,1,64);

%figure
%plot(lags,waveCorr(:,64.*62+20)); axis([-10 10 -1 1]); grid on;
%figure
for n=1:64
subplot(8,8,n); plot(t(900:1100), waveCorr(:,64.*(n-1)+35)); axis([-100 100 -1 1]); grid on; %axis off;
[C(n),I(n)]=max(waveCorr(:,64*(n-1)+35));
end
J=I-I(35);
L=reshape(J,8,8)'
%figure
%interp_L=interp2(L,4,'linear');
%imagesc(interp_L); colorbar('horiz'); %axes off;
%caxis([-100 100]) 
%axis('image')
%axis('off')



   
 