In this folder you find the data and Matlab code used in the paper: "Activity recognition using a single accelerometer placed at the wrist or ankle" by Andrea Mannini, Stephen S Intille, Mary Rosenberger, Angelo M Sabatini and William Haskell. 


%%%%%%%%%%%%%%%%%% DATASET %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Data are stored in .mat files named: 
StanfordDataset2010_("corrected" or "uncorrected")_(Sensor placement site)_MSSE.mat
- "corrected" or "uncorrected" refers to the application or not of the ankle data based correction of labels, based on ankle activity as described in the methods section of the paper.
- Available sensor placement sites are "Ankle" or "Wrist".

The described .mat files contain three structures: 
1) Info: 1x33 structure with information on the dataset for each of the 33 participants.
2) Data: 1x33 structure with windowed data (accelerometer filtered signal magnitude vectors, SMV) and classificaiton features evaluated from data windows, for each of the 33 participants.
3) Labels: 1x33 structure with classification labels, for each of the 33 participants.

The Info structure for each participant data has 7 fields:
-Info.folder = name of the dataset folder where this participant data were stored (correspondig to the date of the experimental session) 
-Info.wocketnumber = sensor ID
-Info.datatype = wockets data typology
-Info.window = window length in milliseconds
-Info.fs = sampling frequency
-Info.activity_labels = ordered list of activity labels
-Info.posture_labels = ordered list of posture labels

Each element of the Data structure has 3 fields:
-Data.raw_m contains the filtered acceleration SMV in each window
-Data.Pm contains the features for classification
-Data.time contains the timestamp of each acceleration sample in milliseconds (starting from 01/01/1970).

The Labels structure has several fields:
-Labels.Lab1, posture labels for each datum
-Labels.Lab2, activity labels for each datum
-Labels.Lab1w, posture labels for each window
-Labels.Lab2w, activity labels for each window
-Labels.Lab5w, classification labels for each window. Five classes considered (1 = running, 2 = walking, 3 = cycling, 4 = other, 5 = sedentary).  In the code, class1 is discarded for the lack of enough running data. 


%%%%%%%%%%%%%%%%%% CODE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

To use the code change your Matlab current directory to the same folder of this readme file.

%% Features evaluation
Features as stored in Data.Pm can be evaluated from filtered acceleration data by using the provided function "evaluatefeatures_MSSE.m". A Matlab script to check the feature extraction is provided ("test_code_features_evaluation.m").

%% Cross validation tests
Cross validation tests as performed for the paper can be executed running the m-file:
"classification_wockets_clean_MSSEpaper.m" 
In the second cell of the script it is possible to choose the Dataset to be used within:
  > Ankle corrected
  > Ankle uncorrected
  > Wrist corrected
  > Wrist uncorrected
In the third cell several parameters can be modified. The most important is the "indiv" parameter. Set it to 0 to run an nfold cross-validation. Set it and the "l10" parameter to 1 to run a LOSO (leave-one-subject-out) cross-validation.

















