display("Generating Features")

#load and plot raw data
#{
data structure of cellarray classes:
classes[1 to 5]
  samples[1 to trainsetPerClass]
    raw[1 to 3] 
      Accel[start:pEnd]
      Gyro[start:pEnd]
      Magnet[start:pEnd]
      
access the cells using classes{u}.samples{v}.raw{w}
#}
source("functions.m");
source("settings.m")
global setWindowSize;

classes = {};
classes = getRawTrainData();

#outPath = "/home/toni/Documents/handygames/HandyGames/toni/img/raw"
#plotData(classes, outPath);

#calc and plot filtered data
filteredClasses = filterData(classes);

#outPath = "/home/toni/Documents/handygames/HandyGames/toni/img/filtered";
#plotData(filteredClasses, outPath);

#create sliding windows and add 6 additional signals pca and magnitude
#{
data structure of windowedClasses:
classes[1 to 5]
  samples[1 to trainsetPerClass]
    raw[1 to 15] <--- 15 different signals
      3x WindowsAccel (X, Y, Z)
        Win, Win, Win, Win ... <--- single matrices
      3x WindowsGyro (X, Y, Z)
        Win, Win, Win, Win ... <--- single matrices
      3x WindowsMagnet (X, Y, Z)
        Win, Win, Win, Win ... <--- single matrices
        
    ---> add 6 additional sensors: pca and magnitude    
      3x WindowsPCA (Accel, Gyro, Magnet)
        Win, Win, Win, Win ... <--- single matrices
      3x WindowsMagnitude (Accel, Gyro, Magnet)
        Win, Win, Win, Win ... <--- single matrices  
        
access the cells using classes{u}.samples{v}.raw{signal, window)

pca uses the eigenvector with the heighest eigenvalue as axis and projects the signals onto it for each sensor. 
magnitude is calculated using sqrt(x^2 + y^2 + z^2) for each sensor. 
#}
windowedClasses = windowData(classes);

#calculated features for the 5 signales (x, y, z, MG, PCA) of a sensor
#{
data structure of features
[classLabel, binMeans, rms, psd, windowMean, windowSTD, windowVariance, windowKurtosis, windowIQR]
#}
features = featureCalculation(windowedClasses);

#save features
name = strcat("features_", num2str(setWindowSize),"_xyz_nomag_psd18.txt");
save(name, 'features');
display("saved features into features.txt");



