diff --git a/oldMcode/readKin.m b/oldMcode/readKin.m new file mode 100644 index 0000000..12525cb --- /dev/null +++ b/oldMcode/readKin.m @@ -0,0 +1,22 @@ +maxFile=5; + +% addpath('/home/hohlochj/masterarbeit/usedMcode') +% pathToFile='/nfs/wsi/ti/messor/hohlochj/origData/'; +pathToFile='/home/jph/Uni/masterarbeit/Block1_ReachingMovements/'; + +[subjects,numbers]=namesAndNumbers(strcat(pathToFile,'dirs.txt')); + +tmp=cell([maxFile,1]); + +for i=1:size(subjects,2) + subject=subjects{i}; + for number=numbers{i} + parfor j=1:maxFile + tmp{j}=csvread(strcat(pathToFile,sprintf('kin/%s_B1S00%iR0%i.txt',subject,number,j)),1,0); + tmp{j}=tmp{j}(:,1:4); + end + eval(sprintf('kin%s%i = tmp;',subject,number)); + end +end + +save(strcat(pathToFile,'kinematics.mat')) \ No newline at end of file diff --git a/text/TODO.txt b/text/TODO.txt index f9d55da..1b5d439 100644 --- a/text/TODO.txt +++ b/text/TODO.txt @@ -1,6 +1,6 @@ -filtfilt +filtfilt (done) -Alle VP auf eciton +Alle VP auf eciton (done) Matching Bewegung EEG - durch interpolation (ridge) diff --git a/usedMcode/callAll.m b/usedMcode/callAll.m index aad1a6f..95c2196 100644 --- a/usedMcode/callAll.m +++ b/usedMcode/callAll.m @@ -1,6 +1,6 @@ addpath('/home/hohlochj/masterarbeit/usedMcode') -pathToFile='/nfs/wsi/ti/messor/hohlochj/origData/dirs.txt'; -% pathToFile='/home/jph/Uni/masterarbeit/Block1_ReachingMovements/dirs.txt'; +pathToFile='/nfs/wsi/ti/messor/hohlochj/origData/'; +% pathToFile='/home/jph/Uni/masterarbeit/Block1_ReachingMovements/'; windowEMG=0.2; windowEEG=1; @@ -14,7 +14,7 @@ EEG=true; poolObj=parpool(32); -[subjects,numbers]=structForAllDays(pathToFile); +[subjects,numbers]=namesAndNumbers(pathToFile); j=0; for i=1:size(subjects,2) subject=subjects{i}; @@ -27,15 +27,15 @@ meanAccurancysEEG=zeros([j,1]); j=1; -parfor i=1:size(subjects,2) +for i=1:size(subjects,2) subject=subjects{i}; for number=numbers{i} % fprintf('%s%i\n',subject,number); - readEEGEciton(subject,number,windowEMG,windowEEG,shift,5,7500,pburgOrder,minEEGFreq,maxEEGFreq); + readEEGEciton(pathToFile,subject,number,windowEMG,windowEEG,shift,5,7500,pburgOrder,minEEGFreq,maxEEGFreq); meanAccurancysEMG(j)=svmEciton(subject,number,false,k,maxExpC,maxPerClass); meanAccurancysEEG(j)=svmEciton(subject,number,EEG,k,maxExpC,maxPerClass); j=j+1; end end -save(sprintf('/nfs/wsi/ti/messor/hohlochj/matlabData/%s_callAll.mat',datestr(datetime('now')))); +%save(sprintf('/nfs/wsi/ti/messor/hohlochj/matlabData/%s_callAll.mat',datestr(datetime('now')))); delete(poolObj) diff --git a/usedMcode/generateTrainingData.m b/usedMcode/generateTrainingData.m index 6cc8601..f62bd88 100644 --- a/usedMcode/generateTrainingData.m +++ b/usedMcode/generateTrainingData.m @@ -1,4 +1,4 @@ -function [trainingDataEEG,trainingDataEMG] = generateTrainingData(signal,windowEMG,windowEEG,shift,params,pburgOrder,minEEGFreq,maxEEGFreq) +function [trainingDataEEG,trainingDataEMG,kinPerSec] = generateTrainingData(signal,kin,windowEMG,windowEEG,shift,params,pburgOrder,minEEGFreq,maxEEGFreq) frequency=params.SamplingRate.NumericValue; signalWindowEMG=frequency*windowEMG; signalWindowEEG=frequency*windowEEG; @@ -20,4 +20,6 @@ tempEMG(i-32,:,:)=waveformLength(filter(C,D,filter(A,B,signal(:,i))),frequency,windowEMG,shift); end trainingDataEMG=permute(tempEMG,[2 1 3]); + + kinPerSec=shiftingKin(kin,frequency,windowEEG,shift); end diff --git a/usedMcode/namesAndNumbers.m b/usedMcode/namesAndNumbers.m new file mode 100644 index 0000000..877ef27 --- /dev/null +++ b/usedMcode/namesAndNumbers.m @@ -0,0 +1,21 @@ +function [names,numbers]=namesAndNumbers(pathToFile) + fileID=fopen(strcat(pathToFile,'dirs,txt'); + text=textscan(fileID,'%s','Delimiter','\n'); + text=text{1}; + j=0; + k=0; + names=cell(1); + for i=1:size(text) + tmp=char(text(i)); + name=strcat(tmp(1:2)); + if (j~=0 && all(squeeze(names{j}==name))) + k=k+1; + numbers{j}(k)=str2double(tmp(end)); + else + j=j+1; + names{j}=name; + k=1; + numbers{j}(k)=str2double(tmp(end)); + end + end +end \ No newline at end of file diff --git a/usedMcode/readEEGEciton.m b/usedMcode/readEEGEciton.m index 69661ee..316f1a7 100644 --- a/usedMcode/readEEGEciton.m +++ b/usedMcode/readEEGEciton.m @@ -1,14 +1,16 @@ -function readEEGEciton(subject,number,windowEMG,windowEEG,shift,maxFile,threshold,pburgOrder,minEEGFreq,maxEEGFreq) +function readEEGEciton(pathToFile, subject,number,windowEMG,windowEEG,shift,maxFile,threshold,pburgOrder,minEEGFreq,maxEEGFreq) %fprintf('start read %s%i %s\n',subject,number,datestr(datetime('now'))); trainingDataEEGcell=cell(maxFile,1); trainingDataEMGcell=cell(maxFile,1); classesCell=cell(maxFile,1); + kin=cell([maxFile,1]); for i=1:maxFile - [sig, stat, params] = load_bcidat(sprintf('/nfs/wsi/ti/messor/hohlochj/origData/%s/%s_B100%i/%s_B1S00%iR0%i.dat',subject,subject,number,subject,number,i)); - [trainingDataEEGcell{i},trainingDataEMGcell{i}]=generateTrainingData(sig,windowEMG,windowEEG,shift,params,pburgOrder,minEEGFreq,maxEEGFreq); + [sig, stat, params] = load_bcidat(strcat(pathToFile,sprintf('%s/%s_B100%i/%s_B1S00%iR0%i.dat',subject,subject,number,subject,number,i))); + tmpKin=csvread(strcat(pathToFile,sprintf('kin/%s_B1S00%iR0%i.txt',subject,number,i)),1,0); + [trainingDataEEGcell{i},trainingDataEMGcell{i},kin{i}]=generateTrainingData(sig,tmpKin,windowEMG,windowEEG,shift,params,pburgOrder,minEEGFreq,maxEEGFreq); classesCell{i}=stat.StimulusCode; %fprintf('%ith file processed\n',i) end @@ -18,7 +20,8 @@ trainingDataEEG=cell2mat(trainingDataEEGcell); trainingDataEMG=cell2mat(trainingDataEMGcell); classesMat=cell2mat(classesCell); - clear trainingDataEEGcell trainingDataEMGcell classesCell + kinMat=cell2mat(kin); + clear trainingDataEEGcell trainingDataEMGcell classesCell kin classificationWithPause=classifyAccordingToEMG(trainingDataEEG, trainingDataEMG,classesMat,shift,params.SamplingRate.NumericValue,threshold); clear classesMat @@ -33,9 +36,10 @@ trainingDataEEG=trainingDataEEG(smoothClassification~=-1,:,:); trainingDataEMG=trainingDataEMG(smoothClassification~=-1,:); classification=smoothClassification(smoothClassification~=-1); + kinematics=kinMat(smoothClassification~=-1,:); clear smoothClassification i - save(sprintf('/nfs/wsi/ti/messor/hohlochj/matlabData/%s%i200msWindowEMG1sWindowEEG200msShift1sPauseFreq0to200.mat',subject,number),'trainingDataEEG','trainingDataEMG','classification','-v7.3'); + save(sprintf('/nfs/wsi/ti/messor/hohlochj/matlabData/%s%i200msWindowEMG1sWindowEEG200msShift1sPauseFreq0to200.mat',subject,number),'trainingDataEEG','trainingDataEMG','classification','kinematics','-v7.3'); %fprintf('end read %s%i %s\n',subject,number,datestr(datetime('now'))); diff --git a/usedMcode/shiftingKin.m b/usedMcode/shiftingKin.m new file mode 100644 index 0000000..4130c76 --- /dev/null +++ b/usedMcode/shiftingKin.m @@ -0,0 +1,6 @@ +function [kinPerSec]=shiftingKin(kin, window, shift) + kinPerSec=zeros(fix((max(kin(:,1))-window*1000)/(shift*1000)),3); + for j=1:fix((max(kin(:,1))-window*1000)/(shift*1000)) + kinPerSec(j,:)=sum(diff(kin(kin(:,1)>=(j-1)*shift*1000 & kin(:,1)<=(j-1)*shift*1000+window*1000,2:4))); + end +end \ No newline at end of file diff --git a/usedMcode/structForAllDays.m b/usedMcode/structForAllDays.m deleted file mode 100644 index d8c5f3a..0000000 --- a/usedMcode/structForAllDays.m +++ /dev/null @@ -1,21 +0,0 @@ -function [names,numbers]=structForAllDays(dirs) - fileID=fopen(dirs); - text=textscan(fileID,'%s','Delimiter','\n'); - text=text{1}; - j=0; - k=0; - names=cell(1); - for i=1:size(text) - tmp=char(text(i)); - name=strcat(tmp(1:2)); - if (j~=0 && all(squeeze(names{j}==name))) - k=k+1; - numbers{j}(k)=str2double(tmp(end)); - else - j=j+1; - names{j}=name; - k=1; - numbers{j}(k)=str2double(tmp(end)); - end - end -end \ No newline at end of file