for i=1:8
    for j=1:length(trials{i})
        start = round(1250*trials{i}{j}(1,5));
        stop = round(1250*trials{i}{j}(end,5));
        [ freqs, tt, spec ] = WaveSpec(lfp(start:stop,2),[1 200],100,5,1/1250,'log');
        ls_wave{i}{j} = abs(spec);
        
        [ freqs, tt, spec ] = WaveSpec(lfp(start:stop,4),[1 200],100,5,1/1250,'log');
        hpc_wave{i}{j} = abs(spec);
    end
end

for i=1:8
    for j=1:length(trials{i})
        
        vel{i}{j} = sum(abs(diff(trials{i}{j}(:,1:4)))');
        v = 1:length(vel{i}{j});
        vv = 1:length(vel{i}{j})/80:length(vel{i}{j});
        
        x=1:length(ls_wave{i}{j});
        xx = 1:length(x)/5000.:length(x);
        c=1;
        while length(xx) < 5000
            xx = 1:length(x)/(5000+c):length(x);
            c=1+c;
        end
        for f =1:80
        y = ls_wave{i}{j}(f,:);
        ls_wave_spline{i}(j,f,:) = spline(x,y,xx);
        y = hpc_wave{i}{j}(f,:);
        hpc_wave_spline{i}(j,f,:) = spline(x,y,xx);
        
        vel_norm{i}(j,:) = spline(v,vel{i}{j},vv);
        end
        
        
    end
end
for i=1:8
for j=1:size(ls_wave_spline{i},2)
for t  = 1:size(ls_wave_spline{i},1)
ls_wave_spline_norm{i}(t,j,:) = zscore(ls_wave_spline{i}(t,j,:));
hpc_wave_spline_norm{i}(t,j,:) = zscore(hpc_wave_spline{i}(t,j,:));
end
end
end

h=[];
 for i=1:8
h = [h;hpc_wave_spline_norm{i}];
 end

 l=[];
for i=1:8
l = [l;ls_wave_spline_norm{i}];
end

v=[];
for i=1:8
v = [v;vel_norm{i}];
end


figure
subplot(2,1,1)
imagesc(1:5000,(freqs),squeeze(mean(l)))
caxis([-.5 .5])
LogScale('y',2)
subplot(2,1,2)
imagesc(1:5000,(freqs),squeeze(mean(h)))
LogScale('y',2)
caxis([-.5 .5])
