function [ DataFeature DataFeatureLabel] = FeaturesTactile(TerrainWindow)
    % function [ features ] = FeaturesTactile(TerrainWindow)
    % TerrainWindow : an array of 1xn samples corresponding to
    % accelerometer data. 
    % DataFeature : the eight features extracted from my paper.
    % DataFeatureLabel : a cell array of strings representing the features
    if (size(TerrainWindow,1) > size(TerrainWindow,2))
        TerrainWindow = TerrainWindow';
    end

    w = size(TerrainWindow,2);
    TerrainSpectrum = abs(fft(TerrainWindow));
    TerrainSpectrum = TerrainSpectrum(1:(w/2));
    sp = size(TerrainSpectrum,2);
    HighFreq = sum(TerrainSpectrum(ceil(sp*0.5):end))/(0.5*w);
    d  = HistogramLineCrossing(TerrainWindow',30)./(30*w);
    ar = sum(d);
    x = var(TerrainWindow);
    y = skewness(TerrainWindow);
    z = kurtosis(TerrainWindow);
    dt = (TerrainWindow(1:(end-1))-TerrainWindow(2:end))/w;

    DataFeature(1) = mean(TerrainWindow);     DataFeatureLabel{1} = 'Mean';
    DataFeature(2) = x;                       DataFeatureLabel{2} = 'Variance';
    DataFeature(3) = y;                       DataFeatureLabel{3} = 'Skewness';
    DataFeature(4) = z;                       DataFeatureLabel{4} = 'Kurtosis';
    DataFeature(5) = moment(TerrainWindow,5); DataFeatureLabel{5} = 'Fifth Moment';
    DataFeature(6) = ar;                      DataFeatureLabel{6} = 'Area of Crossings';
    DataFeature(7) = sum(abs(dt))./w;         DataFeatureLabel{7} = 'Sum of Changes';
    DataFeature(8) = HighFreq;                DataFeatureLabel{8} = 'Sum of High Freq';
return

function ret = HistogramLineCrossing(values,nBin);
ret = 0;
range = max(values)-min(values);
incr = range/nBin;
index = 1;
for threshold = (min(values)+incr):incr:(max(values)-incr)
  ret(index) = LineCrossing(values,threshold);
  index = index+1;
end
if (ret==0)
    display('Some data was problematic. maybe saturation?');
    values
end
return

function c = LineCrossing(values,threshold2);

sizeA = size(values,2);
values = values - threshold2;
% Faster computation
BigAss = values(1:end-1).*values(2:end);
c = sum(BigAss < 0);
return

