generate.m 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. % One need to determine the framesize and frameoffset beforehand...
  2. framesize = 50;
  3. frameoffset = 25;
  4. maxFrameShift = 10;
  5. splitRatio = [70, 20, 10]; % percentage of training, validation, testing needs to add up to 100!!!
  6. file = '2019_08_08_1256';
  7. filepointer = csvread(strcat('AppData/', file, '.csv'), 2, 0);
  8. % get the training data and the labels
  9. [dataset, lbls] = generateTrainingDataFromCSV(filepointer, framesize, frameoffset, maxFrameShift);
  10. % gathering some statistics
  11. % 1. pointerDownTime equals the time a finger is residing on the screen
  12. % 2. timeBetweenTouchEvents indicating the frequency of the taps
  13. % 3. max/min Values of Frames indicating the strength of the taps
  14. POINTERDOWNTIME1 = 14;
  15. POINTERDOWNTIME2 = 15;
  16. TIMEBETWEENTOUCHEVENTS = 16;
  17. indicesPDT1 = find(filepointer(:, POINTERDOWNTIME1) ~= 0);
  18. indicesPDT2 = find(filepointer(:, POINTERDOWNTIME2) ~= 0);
  19. indicesTBT = find(filepointer(:, TIMEBETWEENTOUCHEVENTS) ~= 0);
  20. pointerDownTimes = filepointer(indicesPDT1, POINTERDOWNTIME1);
  21. pointerDownTimes = cat(1, pointerDownTimes, filepointer(indicesPDT1, POINTERDOWNTIME1));
  22. TimeBetweenTouchEvents = filepointer(indicesTBT(2:end), TIMEBETWEENTOUCHEVENTS);
  23. maxGYRO = [max(dataset(:,:,1)')', max(dataset(:,:,2)')', max(dataset(:,:,3)')'];
  24. maxACC = [max(dataset(:,:,4)')', max(dataset(:,:,5)')', max(dataset(:,:,6)')'];
  25. fig1 = figure;
  26. % TODO Something is still wrong with these times...
  27. histogram(pointerDownTimes ./ 1000000) % Divide from ns to ms
  28. title('Histogram of the Duriation of touch events')
  29. fig2 = figure;
  30. histogram(TimeBetweenTouchEvents ./ 1000000) % Divide from ns to ms
  31. title('Histogram of the time between sequential touch events')
  32. fig3 = figure;
  33. subplot(2,3,1)
  34. nbins = 10;
  35. histogram(maxGYRO(:, 1), nbins)
  36. title('Hist Max Gyro X')
  37. subplot(2,3,2)
  38. histogram(maxGYRO(:, 2), nbins)
  39. title('Hist Max Gyro Y')
  40. subplot(2,3,3)
  41. histogram(maxGYRO(:, 3), nbins)
  42. title('Hist Max Gyro Z')
  43. subplot(2,3,4)
  44. histogram(maxACC(:, 1), nbins)
  45. title('Hist Max ACC X')
  46. subplot(2,3,5)
  47. histogram(maxACC(:, 2), nbins)
  48. title('Hist Max ACC Y')
  49. subplot(2,3,6)
  50. histogram(maxACC(:, 3), nbins)
  51. title('Hist Max ACC Z')
  52. % shuffle the dataset
  53. shuffle = randperm(size(dataset, 3));
  54. dataset = dataset(:, :, shuffle);
  55. lbls = lbls(:, shuffle);
  56. % split into seperate sets and save them as mat (normalization will be done
  57. % in julia)
  58. splitTrain = floor(size(dataset, 3) * splitRatio(1) / 100 )
  59. data = dataset(:, :, 1:splitTrain);
  60. labels = lbls(:, 1:splitTrain);
  61. save(strcat('TrainingData/', file, '_TRAIN_.mat'),'data', 'labels')
  62. splitVal = floor(size(dataset, 3) * (splitRatio(2) + splitRatio(1)) / 100 )
  63. data = dataset(:, :, splitTrain+1:splitVal);
  64. labels = lbls(:, splitTrain+1:splitVal);
  65. save(strcat('TrainingData/', file, '_VAL_.mat'),'data', 'labels')
  66. data = dataset(:, :, splitVal+1:end);
  67. labels = lbls(:, splitVal+1:end);
  68. save(strcat('TrainingData/', file, '_TEST_.mat'),'data', 'labels')