
animalNames = {'LIMP014_012';
    'LIMP014_014';
    'LIMP016_004';
    'LIMP018_003'};
%
for anID = 1:length(animalNames)
    Names_LIMP = dir([animalNames{anID},'*WAKE_Trough*lfpChan.mat']);
    filenamesLIMP= {Names_LIMP.name};
    foldernameLIMP = {Names_LIMP.folder};
    load(fullfile(foldernameLIMP{1},filenamesLIMP{1}));
    figure;
    set(gcf,'Position',[100 100 500 300])
    h = pcolor(downsample(wavAvg.timestamps,50),wavAvg.freqs,downsample(wavAvg.data,50)');hold on;
    set(h, 'EdgeColor', 'none');
    shading interp;
    set(gca,'YDir','normal')
    set(gca,'YScale','log');
    colormap('jet')
    xlabel('time (ms)'); ylabel('frequency (Hz)');
    colorbar
    clim([40, 120])
    yyaxis right
    df = diff(wavAvg.freqs);
    wavAvg2 = 0.5*(wavAvg.data(:,2:end) + wavAvg.data(:,1:end-1));
    wavAvg2_band = wavAvg2.*df;
    Fband = wavAvg.freqs(76)-wavAvg.freqs(87);
    wavAvg_smoothed = smoothdata(mean(wavAvg2_band(:,76:87),2),'sgolay',2e3);
    plot(wavAvg.timestamps,wavAvg_smoothed,'k')
    
    fs_ripple = 1250;
    PWake_Trough(anID) = 100*(-mean(wavAvg_smoothed(1:5*fs_ripple)) +  mean(wavAvg_smoothed(15*fs_ripple:20*fs_ripple)))/mean(wavAvg_smoothed(1:5*fs_ripple))
end


%
for anID = 1:length(animalNames)
    Names_LIMP = dir([animalNames{anID},'*WAKE_Peak*lfpChan.mat']);
    filenamesLIMP= {Names_LIMP.name};
    foldernameLIMP = {Names_LIMP.folder};
    load(fullfile(foldernameLIMP{1},filenamesLIMP{1}));
    figure;
    set(gcf,'Position',[100 100 500 300])
    h = pcolor(downsample(wavAvg.timestamps,50),wavAvg.freqs,downsample(wavAvg.data,50)');hold on;
    set(h, 'EdgeColor', 'none');
    shading interp;
    set(gca,'YDir','normal')
    set(gca,'YScale','log');
    colormap('jet')
    xlabel('time (ms)'); ylabel('frequency (Hz)');
    colorbar
    yyaxis right
    df = diff(wavAvg.freqs);
    wavAvg2 = 0.5*(wavAvg.data(:,2:end) + wavAvg.data(:,1:end-1));
    wavAvg2_band = wavAvg2.*df;
    Fband = wavAvg.freqs(76)-wavAvg.freqs(87);
    wavAvg_smoothed = smoothdata(mean(wavAvg2_band(:,76:87),2),'sgolay',2e3);
    plot(wavAvg.timestamps,wavAvg_smoothed,'k')
    
    fs_ripple = 1250;
    PWake_Peak(anID) = 100*(-mean(wavAvg_smoothed(1:5*fs_ripple)) +  mean(wavAvg_smoothed(15*fs_ripple:20*fs_ripple)))/mean(wavAvg_smoothed(1:5*fs_ripple))
end

%%
Wake_Peak = PWake_Peak';
Wake_Trough = PWake_Trough';

Ach_Results = table(Wake_Trough,Wake_Peak);
%%
colr = [1.0,0,0];
scatter([0,1],Ach_Results{3,:},70,colr,'o',LineWidth=2)
hold on
scatter([0,1],Ach_Results{4,:},70,colr,'d',LineWidth=2)
scatter([0,1],Ach_Results{2,:},70,colr,'s',LineWidth=2)
scatter([0,1],Ach_Results{1,:},70,colr,'p',LineWidth=2)

xlim([-0.5,2])
yline([0],'--')


%%
animalNames = {'OXYT010_004';
    'OXYT011_005';
    'OXYT014_001';
    'OXYT012_001'};

%
for anID = 1:length(animalNames)
    Names_LIMP = dir([animalNames{anID},'*WAKE_Trough*lfpChan.mat']);
    filenamesLIMP= {Names_LIMP.name};
    foldernameLIMP = {Names_LIMP.folder};
    load(fullfile(foldernameLIMP{1},filenamesLIMP{1}));
    figure;
    set(gcf,'Position',[100 100 500 300])
    h = pcolor(downsample(wavAvg.timestamps,50),wavAvg.freqs,downsample(wavAvg.data,50)');hold on;
    set(h, 'EdgeColor', 'none');
    shading interp;
    set(gca,'YDir','normal')
    set(gca,'YScale','log');
    colormap('jet')
    xlabel('time (ms)'); ylabel('frequency (Hz)');
    colorbar
    clim([40, 120])
    yyaxis right
    df = diff(wavAvg.freqs);
    wavAvg2 = 0.5*(wavAvg.data(:,2:end) + wavAvg.data(:,1:end-1));
    wavAvg2_band = wavAvg2.*df;
    Fband = wavAvg.freqs(76)-wavAvg.freqs(87);
    wavAvg_smoothed = smoothdata(mean(wavAvg2_band(:,76:87),2),'sgolay',2e3);
    plot(wavAvg.timestamps,wavAvg_smoothed,'k')
    
    fs_ripple = 1250;
    PWake_Trough(anID) = 100*(-mean(wavAvg_smoothed(1:5*fs_ripple)) +  mean(wavAvg_smoothed(15*fs_ripple:20*fs_ripple)))/mean(wavAvg_smoothed(1:5*fs_ripple))
end


%
for anID = 1:length(animalNames)
    Names_LIMP = dir([animalNames{anID},'*WAKE_Peak*lfpChan.mat']);
    filenamesLIMP= {Names_LIMP.name};
    foldernameLIMP = {Names_LIMP.folder};
    load(fullfile(foldernameLIMP{1},filenamesLIMP{1}));
    figure;
    set(gcf,'Position',[100 100 500 300])
    h = pcolor(downsample(wavAvg.timestamps,50),wavAvg.freqs,downsample(wavAvg.data,50)');hold on;
    set(h, 'EdgeColor', 'none');
    shading interp;
    set(gca,'YDir','normal')
    set(gca,'YScale','log');
    colormap('jet')
    xlabel('time (ms)'); ylabel('frequency (Hz)');
    colorbar
    yyaxis right
    df = diff(wavAvg.freqs);
    wavAvg2 = 0.5*(wavAvg.data(:,2:end) + wavAvg.data(:,1:end-1));
    wavAvg2_band = wavAvg2.*df;
    Fband = wavAvg.freqs(76)-wavAvg.freqs(87);
    wavAvg_smoothed = smoothdata(mean(wavAvg2_band(:,76:87),2),'sgolay',2e3);
    plot(wavAvg.timestamps,wavAvg_smoothed,'k')
    
    fs_ripple = 1250;
    PWake_Peak(anID) = 100*(-mean(wavAvg_smoothed(1:5*fs_ripple)) +  mean(wavAvg_smoothed(15*fs_ripple:20*fs_ripple)))/mean(wavAvg_smoothed(1:5*fs_ripple))
end

%%
Wake_Peak = PWake_Peak';
Wake_Trough = PWake_Trough';

Oxt_Results = table(Wake_Trough,Wake_Peak);
%%
colr = [0,0.5,0];
figure
scatter([0.5, 1.5],Oxt_Results{3,:},70,colr,'o',LineWidth=2)
hold on
scatter([0.5, 1.5],Oxt_Results{4,:},70,colr,'d',LineWidth=2)
scatter([0.5, 1.5],Oxt_Results{2,:},70,colr,'s',LineWidth=2)
scatter([0.5, 1.5],Oxt_Results{1,:},70,colr,'p',LineWidth=2)

xlim([-0.5,2])
yline([0],'--')