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

function [data] = PlotCrossCorr6( wave );

%waveFilt = bandFilter(wave(:,1:64),3,60);
%waveFilt = BudapestbandPass(wave,1000,5,200);
[waveCorr,lags] = xcov(wave(1:300,1:48),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(lags, waveCorr(:,64.*(n-1)+12)); axis([-10 10 -1 1]); grid on; %axis off;
%end
%figure
%plot(lags,waveCorr(:,64.*62+20)); axis([-100 100 -1 1]); grid on;
%figure
%for n=1:64
%subplot(8,8,n); plot(lags, waveCorr(:,64.*(n-1)+20)); axis([-100 100 -1 1]); grid on; %axis off;
%end

%----------For hori ******************CHECK WHICH NUMBER IT'LL REALLY BE!
figure
plot(lags,waveCorr(:,48.*47+10)); axis([-200 200 -1 1]);
figure
for n=1:48
subplot(8,6,n); plot(lags, waveCorr(:,48*(n-1)+n)); axis([-200 200 -1 1]); axis off;
end

%----------For verti ******************CHECK WHICH NUMBER IT'LL REALLY BE!
%figure
%plot(lags,waveCorr(:,48.*22+22)); axis([-200 200 -1 1]);
%figure
%for n=1:48
%subplot(6,8,n); plot(lags, waveCorr(:,48*(n-1)+n)); axis([-200 200 -1 1]); axis off;
%end

%----------For hori ******************CHECK WHICH NUMBER IT'LL REALLY BE!
for n=1:48
[C(n),I(n)]=max(waveCorr(:,48*(n-1)+12));
end
J=I-I(12);
L=reshape(J,6,8)'
figure
interp_L=interp2(L,4,'linear');
imagesc(interp_L); colorbar('horiz'); %axes off;
axis('image')
axis('off')

%----------For verti ******************CHECK WHICH NUMBER IT'LL REALLY BE!
%for n=1:48
%[C(n),I(n)]=max(waveCorr(:,48*(n-1)+12));
%end
%J=I-I(12);
%L=reshape(J,8,6)'
%figure
%interp_L=interp2(L,4,'linear');
%imagesc(interp_L); colorbar('horiz'); %axes off;
%axis('image')
%axis('off')