for i=1:8
subplot(2,4,i); hold off
for j=1:length(trials{i})
start = round(trials{i}{j}(1,1)*1250);
stop = round(trials{i}{j}(end,1)*1250);

for k=1:length(locs)
[a b] = min(abs(locs(k)-locs2));
st = start./1250+locs(k)/1250;
[aa bb] = min(abs(trials{i}{j}(:,1)-st));
scatter(trials{i}{j}(bb,8),trials{i}{j}(bb,10),b,'.k')
hold on
end
pause; hold off;end
end
 
for i=1:8
%  hold off
%  subplot(2,4,i)
for j=1:length(trials{i})
start = round(trials{i}{j}(1,1)*1250);
stop = round(trials{i}{j}(end,1)*1250);

% [pks locs] = findpeaks(phase(start:stop,1));
% [pks2 locs2] = findpeaks(phase(start:stop,7));
% for k=1:length(locs)
% [a b] = min(abs(locs(k)-locs2));b = locs(k) - locs2(b);
% st = start./1250+locs(k)/1250;
% [aa bb] = min(abs(trials{i}{j}(:,1)-st));
% % scatter(trials{i}{j}(bb,1),trials{i}{j}(bb,10),b,'.k') % actual position
% bbb = mapping{i}{j}(bb,13);
% % scatter(bbb,b,'.k') % normalized distance
% % subplot(2,1,2);
% % scatter(locs(k),b,'.g')
% hold on
% end

[freqs,t,spec] = WaveSpec(lfp(start:stop,2),[1 30],[60],5,1/1250,'lin');
[freqs,t,spec2] = WaveSpec(lfp(start:stop,8),[1 30],[60],5,1/1250,'lin');
% subplot(2,2,1)
% imagesc((abs(spec)))
subplot(2,1,2)
plot(lfp(start:stop,2),'r')
hold on
plot(lfp(start:stop,8),'k')
hold off
% 
for ii=1:60
    sp(j,ii,:)=interp1(1:length(spec),abs(spec(ii,:)),1:length(spec)/200:length(spec));
    sp2(j,ii,:)=interp1(1:length(spec2),abs(spec2(ii,:)),1:length(spec2)/200:length(spec2));
end

end
subplot(2,2,2)
imagesc(squeeze(mean(sp2)))
subplot(2,2,1)
imagesc(squeeze(mean(sp)))
pause
clear sp sp2
end



























