clear all;
path = 'C:\Users\Schmidt\Desktop\data';
str_dat=dir(fullfile(path,'*.txt'));
N=size(str_dat,1);

% collect one group of the data
% we assume that separate groups are in separate folders (just to simplify it)
% you can offcourse change the procedure...
% it is dedicated to the files named like
% '1369726030046-training-true-action-U-type-lacc', where lacc denotes
% linear acceleration
% the data were collected using the exemplary app available on our web page
data_lacc = []; % all the examples (with their features) we collected - only the group U
for j=1:N
    name = str_dat(j,1).name
    data_lacc_new=[];
    f = strfind(name,'-U-'); % linear acceleration part
    if ~isempty(f)
        f = strfind(name,'lacc'); % linear acceleration part
        if ~isempty(f)
        dat = importdata(fullfile(path,name));
        % standard features:
        ft = [mean(dat(:,2:4)) std(dat(:,2:4)) median(dat(:,2:4)) max(dat(:,2:4)) min(dat(:,2:4))];
        % another features
        % few (5) first maximum values (mean of them)
        m = [];
        for k=1:3
             k = dat(:,k+1);
             k = sort(k,'descend');
             mx = mean(k(1:5));
             m = [m mx];
        end
        % features od derivative
        dff = diff(dat);
        dff_dv = dff(:,2:4)./repmat(dff(:,1),[1,3]);
        ft_dv = [mean(dff_dv) std(dff_dv) median(dff_dv) max(dff_dv) min(dff_dv)];
        data_lacc_new = [ft m ft_dv];
        end
    end
    data_lacc=[data_lacc;data_lacc_new];
end
data_orient=[];
for j=1:N
    name = str_dat(j,1).name
    data_orient_new=[];
    f = strfind(name,'-U-'); % linear acceleration part
    if ~isempty(f)
        f = strfind(name,'orient'); % linear acceleration part
        if ~isempty(f)
        dat = importdata(fullfile(path,name));
        % standard features:
        ft = [mean(dat(:,2:4)) std(dat(:,2:4)) median(dat(:,2:4)) max(dat(:,2:4)) min(dat(:,2:4))];
        % another features
        % few (5) first maximum values (mean of them)
        m = [];
        for k=1:3
             k = dat(:,k+1);
             k = sort(k,'descend');
             mx = mean(k(1:5));
             m = [m mx];
        end
        % features od derivative
        dff = diff(dat);
        dff_dv = dff(:,2:4)./repmat(dff(:,1),[1,3]);
        ft_dv = [mean(dff_dv) std(dff_dv) median(dff_dv) max(dff_dv) min(dff_dv)];
        data_orient_new = [ft m ft_dv];
        end
    end
    data_orient=[data_orient;data_orient_new];
end

data = [data_lacc data_orient]; % data for the analysis