addpath('/home/hohlochj/masterarbeit/usedMcode')
pathToFile='/nfs/wsi/ti/messor/hohlochj/origData/';
%pathToFile='/home/jph/Uni/masterarbeit/Block1_ReachingMovements/';

maxFile=5;
threshold=10000; %EMG is classified as movement

windowEMG=0.2; %try 1s
windowEEG=1;
shift=0.2;
pburgOrder=50;
minEEGFreq=0; %try 8-30
maxEEGFreq=200;
pause=false;
ridgeParams=[0.1];
k=10;
maxExpC=0;
maxPerClass=250;
EEG=true;
poolObj=parpool(32);

[subjects,numbers]=namesAndNumbers(pathToFile);
numbersMat=cell2mat(numbers);
subjectsForNumbers=cell(size(numbersMat,2),1);
j=1;
for i=1:size(subjects,2)
    subject=subjects{i};
    for number=numbers{i} 
        subjectsForNumbers{j}=subject;
        j=j+1;
    end
end
j=j-1;

meanAccurancysEMG=zeros([j,1]);
meanAccurancysEEG=zeros([j,1]);
maxCEMG=zeros([j,k,1]);
maxCEEG=zeros([j,k,1]);
cmScaledEMG=zeros([j,5,5]);
cmScaledEEG=zeros([j,5,5]);
correlationEMG=zeros([j,3]); %x,y,angle
correlationEEG=zeros([j,3]);

parfor j=1:size(numbersMat,2)
    number=numbersMat(j);
    subject=subjectsForNumbers{j};
    readEEG(pathToFile,subject,number,windowEMG,windowEEG,shift,maxFile,threshold,pburgOrder,minEEGFreq,maxEEGFreq,pause);
    [meanAccurancysEMG(j),maxCEMG(j,:),cmScaledEMG(j,:,:)]=svmEciton(pathToFile,subject,number,~EEG,k,maxExpC,maxPerClass,windowEMG,windowEEG,shift,minEEGFreq,maxEEGFreq,pause);
    [meanAccurancysEEG(j),maxCEEG(j,:),cmScaledEEG(j,:,:)]=svmEciton(pathToFile,subject,number,EEG,k,maxExpC,maxPerClass,windowEMG,windowEEG,shift,minEEGFreq,maxEEGFreq,pause);
    [correlationEMG(j,:)]=ridgeCV(pathToFile,subject,number,false,k,ridgeParams,windowEMG,windowEEG,shift,minEEGFreq,maxEEGFreq,pause);
    [correlationEEG(j,:)]=ridgeCV(pathToFile,subject,number,EEG,k,ridgeParams,windowEMG,windowEEG,shift,minEEGFreq,maxEEGFreq,pause);
end

save(strcat(pathToFile,sprintf('../matlabData/%s_callAll.mat',datestr(datetime('now')))));
delete(poolObj)


