%params
NFFT=2048;
cutWindowEEG=2;
window=0.2;
shift=0.05;
k=10;
rounds=1;
maxExpC=7;

%svm
load('/home/jph/Uni/masterarbeit/data/AO1.mat');

[ splitSignals, code ] = cutMovements( stimulusCodes, signal );
%[ splitSignals, code ] = cutWindows( stimulusCodes, signal, params, cutWindow );

%trainingData has format trial x ch x powerSpectrum
[trainingDataEEG,trainingDataEMG]=generateTrainingData(splitSignals,NFFT,window,shift,params,cutWindowEEG);

%classify for different movements and rest
classification=zeros(size(code));
for i=1:size(code)
    if code(i)<=5
        classification(i)=code(i);
    else
        classification(i)=0;
    end
end


%classify for move/rest
% cann't use cutMovements then
%classification=double(code<=5);

%choose to estimate based on EEG or EMG
trainingData=trainingDataEEG;


accurancy=zeros(rounds,3);
means=zeros(rounds,1);
for i=1:k
    randMap=randperm(size(trainingData,1));
    leaveOut=trainingData(mod(randMap,k+1)==i,:,:);
    leaveClasses=classification(mod(randMap,k+1)==i);
    remaining=trainingData(mod(randMap,k+1)~=i,:,:);
    remainingClasses=classification(mod(randMap,k+1)~=i);

    model=kfoldCV(remainingClasses,remaining,k,maxExpC);

    [predictions,accurancy(i,:),pvalues]=svmpredict(leaveClasses,leaveOut(:,:),model);
    means(i)=mean(leaveClasses-predictions); %confusion matrix
    %cf: for each cue what was the prediction (maybe colourCoded)
end
meanAccurancy=mean(accurancy(:,1))