generate.m 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. % One need to determine the framesize and frameoffset beforehand...
  2. framesize = 48;
  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_16_1856';
  7. % read the csv and start in the second row, first column
  8. csvData = csvread(strcat('AppData/', file, '.csv'), 2, 0);
  9. % split into seperate sets and save them as mat (normalization will be done
  10. % in julia)
  11. [train_data, train_lbls] = generateTrainingDataFromCSV(csvData, 0, splitRatio(1), framesize, frameoffset, maxFrameShift);
  12. [validation_data, validation_lbls] = generateTrainingDataFromCSV(csvData, splitRatio(1), splitRatio(2), framesize, frameoffset, maxFrameShift);
  13. [test_data, test_lbls] = generateTrainingDataFromCSV(csvData, splitRatio(2) + splitRatio(1), splitRatio(3), framesize, frameoffset, maxFrameShift);
  14. % shuffle the datasets
  15. shuffleSet(train_data, train_lbls);
  16. shuffleSet(validation_data, validation_lbls);
  17. shuffleSet(test_data, test_lbls);
  18. data = train_data;
  19. labels = train_lbls;
  20. save(strcat('TrainingData/', file, '_TRAIN.mat'),'data', 'labels')
  21. data = validation_data;
  22. labels = validation_lbls;
  23. save(strcat('TrainingData/', file, '_VAL.mat'),'data', 'labels')
  24. data = test_data;
  25. labels = test_lbls;
  26. save(strcat('TrainingData/', file, '_TEST.mat'),'data', 'labels')
  27. dataset = cat(3, train_data, validation_data, test_data);
  28. % gathering some statistics
  29. % 1. pointerDownTime equals the time a finger is residing on the screen
  30. % 2. timeBetweenTouchEvents indicating the frequency of the taps
  31. % 3. max/min Values of Frames indicating the strength of the taps
  32. POINTERDOWNTIME1 = 14;
  33. POINTERDOWNTIME2 = 15;
  34. TIMEBETWEENTOUCHEVENTS = 16;
  35. indicesPDT1 = find(csvData(:, POINTERDOWNTIME1) ~= 0);
  36. indicesPDT2 = find(csvData(:, POINTERDOWNTIME2) ~= 0);
  37. indicesTBT = find(csvData(:, TIMEBETWEENTOUCHEVENTS) ~= 0);
  38. pointerDownTimes = csvData(indicesPDT1, POINTERDOWNTIME1);
  39. pointerDownTimes = cat(1, pointerDownTimes, csvData(indicesPDT1, POINTERDOWNTIME1));
  40. TimeBetweenTouchEvents = csvData(indicesTBT(2:end), TIMEBETWEENTOUCHEVENTS);
  41. maxGYRO = [max(dataset(:,:,1)')', max(dataset(:,:,2)')', max(dataset(:,:,3)')'];
  42. maxACC = [max(dataset(:,:,4)')', max(dataset(:,:,5)')', max(dataset(:,:,6)')'];
  43. fig1 = figure;
  44. histogram(pointerDownTimes ./ 1000000) % Divide from ns to ms
  45. title('Histogram of the Duriation of touch events in ms')
  46. fig2 = figure;
  47. histogram(TimeBetweenTouchEvents ./ 1000000) % Divide from ns to ms
  48. title('Histogram of the time between sequential touch events in ms')
  49. fig3 = figure;
  50. subplot(2,3,1)
  51. nbins = 10;
  52. histogram(maxGYRO(:, 1), nbins)
  53. title('Hist Max Gyro X')
  54. subplot(2,3,2)
  55. histogram(maxGYRO(:, 2), nbins)
  56. title('Hist Max Gyro Y')
  57. subplot(2,3,3)
  58. histogram(maxGYRO(:, 3), nbins)
  59. title('Hist Max Gyro Z')
  60. subplot(2,3,4)
  61. histogram(maxACC(:, 1), nbins)
  62. title('Hist Max ACC X')
  63. subplot(2,3,5)
  64. histogram(maxACC(:, 2), nbins)
  65. title('Hist Max ACC Y')
  66. subplot(2,3,6)
  67. histogram(maxACC(:, 3), nbins)
  68. title('Hist Max ACC Z')
  69. function [dataset, labels] = shuffleSet(data, lbls)
  70. shuffle = randperm(size(data, 3));
  71. dataset = data(:, :, shuffle);
  72. labels = lbls(:, shuffle);
  73. end