clear all; clc;

files = dir('*.mat');

for ii = 1:length(files)

    load(files(ii).name)
    figure
    contourf(wavAvg.timestamps*1000,wavAvg.freqs,wavAvg.data',30,'LineColor','none');hold on;
    set(gca,'YScale','log');ylim([0.5 400]);
    % ylim([wavespec.freqs(1) wavespec.freqs(end)]);
    colormap jet;
    xlabel('time (ms)'); ylabel('frequency (Hz)');
    waveAvg_all(:,:,ii) = wavAvg.data;
   

end
data = mean(waveAvg_all,3);
xq = [1:12.5:length(data)];
x = [1:length(data)];
wave_ts = interp1(x,wavAvg.timestamps,xq);
wave_data =[]
for jj = 1:size(data,2)
    
    wave_data(:,jj) = interp1(x,data(:,jj),xq);
 
end

figure
contourf(wave_ts*1000,wavAvg.freqs,wave_data',30,'LineColor','none');hold on;
set(gca,'YScale','log');ylim([0.5 400]);
% ylim([wavespec.freqs(1) wavespec.freqs(end)]);
colormap jet;
xlabel('time (ms)'); ylabel('frequency (Hz)');

figure
contourf(wave_ts,wavAvg.freqs(:,1:91),wave_data(:,1:91)',30,'LineColor','none');hold on;
set(gca,'YScale','log');ylim([0.5 10]);xlim([-10 20]);
colormap jet;
xlabel('time (ms)');
exportgraphics(gcf,'wavelet_all_1-10hz.pdf','BackgroundColor','none','ContentType','vector')

figure
contourf(wave_ts,wavAvg.freqs(:,90:112),wave_data(:,90:112)',30,'LineColor','none');hold on;
set(gca,'YScale','log');ylim([10 20]); clim([70 140]);xlim([-10 20]);
colormap jet;
xlabel('time (ms)');
exportgraphics(gcf,'wavelet_all_10-20hz.pdf','BackgroundColor','none','ContentType','vector')

figure
contourf(wave_ts,wavAvg.freqs(:,158:200),wave_data(:,158:200)',30,'LineColor','none');hold on;
set(gca,'YScale','log');ylim([100 250]);clim([100 180]);xlim([-10 20]);
colormap jet;
xlabel('time (ms)');
exportgraphics(gcf,'wavelet_all_100-250hz.pdf','BackgroundColor','none','ContentType','vector')
%%
%%
aa = [];bb = [];cc = [];

data  = wavAvg.freqs,wave_data;

aa(:,1) = mean(data(1:5000,:),1);
aa(:,2) = std(data(1:5000,:),0,1)./sqrt(7);


bb(:,1) = mean(data(5001:10000,:),1);
bb(:,2) = std(data(5001:10000,:),0,1)./sqrt(7);

cc(:,1) = mean(data(10001:15000,:),1);
cc(:,2) = std(data(10001:15000,:),0,1)./sqrt(7);