%% Control
clear all
cd('G:\My Drive\Paper_ACh_OXT\Fig8\CNO')

files = dir('*.mat');

for ii = 1:5
    load(files(ii).name)

    %% computing the pop_rate
    spikes = OXT_CNO.spikes;
    
   
    smoothingWindow = 10;
    
    data = spikes.data;
    popRate = zeros(length(data),1);
    Nber = size(data,2);
    for spk = 1:Nber
        popRate = popRate + zscore(Smooth(data(:,spk),smoothingWindow));
    end
    popRate = popRate./spk;
    popRate = popRate + abs(min(popRate));
    popRate = smoothdata(popRate,'gaussian',500);

    ripples = OXT_CNO.ripples;
    IDX = round(ripples.timestamps*100);
    for kk = 1:length(ripples.peaks)
        popRate(IDX(kk,1):IDX(kk,2)) = min(popRate);
    end


    datpath = 'G:\My Drive\Paper_ACh_OXT\Fig8\CNO';
    OXT_CNO.popRate_noRip = popRate;
    save(fullfile(datpath,[files(ii).name(1:25),'OXT_CNO.mat']),'OXT_CNO');
    
end

