% Object FID
raw_dir = dir('C:\Users\Jon\Desktop\2010-12-21_Optimus-16259_21div_CNQX-and-Decodability\Stimulation-Data\2010-12-21_16259-Optimus*');

for i = 1:length(raw_dir)
    
    cd(['C:\Users\Jon\Desktop\2010-12-21_Optimus-16259_21div_CNQX-and-Decodability\Stimulation-Data\' raw_dir(i).name])
    
    exp_dir = {'pretrial-30min','trial1','trial2'};
    
    for j = 1:length(exp_dir)
        cd(exp_dir{j})
        
        fileinfo = dir([pwd '\*.spk']);    
        fid = fileinfo(1).name(1:end-4);

        % Load data into data structs
        spkdat = loadspike([pwd '\' fid '.spk']);
        stimdat = loadstim([pwd '\' fid '.stim']);

        % Instantiate a SqueakySpk Object
        SS = SqueakySpk(fid,25000,1,spkdat,stimdat);

        % Remove meaningless channels
        SS.RemoveChannel();
        SS.RemoveChannel([22,35,27]);

        % Remove spikes with blanks
        SS.RemoveSpkWithBlank();

        % Perform a hard p2p cut at 250 uV
        SS.HardThreshold(160,20);

        % Remove waveforms that are quite symmetric about their mean value
        SS.RemoveBySymmetry(0.80);

        % Clustering
        SS.WaveClus(3,20,'wav',1);

        SS.Save;
        
        cd ..
    end
   
    
end