close all
clear variables
%params
disp('start')
disp(datestr(datetime('now')))
windowEMG=0.2;
windowEEG=1;
shift=0.2;
k=10;
maxExpC=5;
maxFile=5;
threshold=7500;
pburgOrder=32;
minEEGFreq=0; %Hz
maxEEGFreq=200; %Hz


trainingDataEEGcell=cell(maxFile,1);
trainingDataEMGcell=cell(maxFile,1);
classesCell=cell(maxFile,1);

for i=1:maxFile
    [sig, stat, params] = load_bcidat(sprintf('/home/jph/Uni/masterarbeit/Block1_ReachingMovements/AO/AO_B1001/AO_B1S001R0%i.dat',i));
    [trainingDataEEGcell{i},trainingDataEMGcell{i}]=generateTrainingData(sig,windowEMG,windowEEG,shift,params,pburgOrder,minEEGFreq,maxEEGFreq);
    classesCell{i}=stat.StimulusCode;
    fprintf('%ith file processed\n',i)
end

clear sig

trainingDataEEG=cell2mat(trainingDataEEGcell);
trainingDataEMG=cell2mat(trainingDataEMGcell);
classesMat=cell2mat(classesCell);
clear trainingDataEEGcell trainingDataEMGcell classesCell

classificationWithPause=classifyAccordingToEMG(trainingDataEEG, trainingDataEMG,classesMat,shift,params.SamplingRate.NumericValue,threshold);
clear classesMat

smoothClassification=zeros(size(classificationWithPause));
for i=1:size(classificationWithPause,1)
    smoothClassification(i)=round(mode(classificationWithPause(max(i-2,1):min(i+2,end))));       
end

clear classificationWithPause

trainingDataEEG=trainingDataEEG(smoothClassification~=-1,:,:);
trainingDataEMG=trainingDataEMG(smoothClassification~=-1,:);
classification=smoothClassification(smoothClassification~=-1);

clear smoothClassification i
save /home/jph/Uni/masterarbeit/data/AO1200msWindow1sPause.mat


disp('end')
disp(datestr(datetime('now')))
