% load relevant spike files
x1 = loadspk('trouble22478_12DIV_nodrug_01.spk');
x2 = loadspk('trouble22468_13DIV_40uM-CNQX-ChR2-stim-CL_02.spk');

% remove bad channels
x1.time = x1.time(~ismember(x1.channel,[52 55 60])==1);
x1.unit = x1.unit(~ismember(x1.channel,[52 55 60])==1);
x1.channel = x1.channel(~ismember(x1.channel,[52 55 60])==1);
x1.threshold = x1.threshold(~ismember(x1.channel,[52 55 60])==1);
x1.waveform = x1.waveform(:,~ismember(x1.channel,[52 55 60])==1);

% concatenate spike data
time = [x1.time; x2.time+max(x1.time)];
channel = [x1.channel; x2.channel];
unit = [x1.unit; x2.unit];
waveform = [x1.waveform x2.waveform];
threshold = [x1.threshold; x2.threshold];
timestamps = [max(x1.time) max(x2.time)+max(x1.time)];

save trouble22468_waveforms_12-14DIV time channel unit timestamps waveform threshold;

%% No manipulation of spikes
clear all;
spkdat = load('trouble22468_waveforms_12-14DIV.mat');
SS = SqueakySpk('trouble22468_12-14DIV_DoublePeakSortNR',2500,1,spkdat);
SS.Save;


%% Wavelet Approach
clear all;
spkdat = load('trouble22468_waveforms_12-14DIV.mat');
SS = SqueakySpk('trouble22468_12-14DIV_WaveletSort',2500,1,spkdat);
SS.WaveClus(4,50,'wav',0,0);
SS.Save;


%% PCA Approach
clear all;
spkdat = load('trouble22468_waveforms_12-14DIV.mat');
SS = SqueakySpk('trouble22468_12-14DIV_PCASort',2500,1,spkdat);
SS.WaveClus(4,50,'pca',0,0);
SS.Save;

%% Line Sort
clear all;
spkdat = load('trouble22468_waveforms_12-14DIV.mat');
SS = SqueakySpk('trouble22468_12-14DIV_LineSort',2500,1,spkdat);

SS.Save;