function [features,info,frameLimits] = extractSignalFeatures(x)
% EXTRACTSIGNALFEATURES Extract signal features
% [FEATURES,INFO,FRAMELIMITS] = extractSignalFeatures(X) returns a matrix
% containing features extracted from input X, INFO, a structure that maps
% a specific feature to its column location in the output feature matrix
% and FRAMELIMITS, whose i-th row contains the beginning and end limits
% of the i-th frame.
%
% Parameters of the signalTimeFeatureExtractor used to generate this
% function must be honored when calling this function.
% Generated by MATLAB(R) 9.11 and Signal Processing Toolbox 8.7.
% Generated on: 10-Jun-2021 08:25:02.
%#codegen
if istimetable(x)
xInTT = x{:,:};
else
xInTT = x;
end
if isrow(xInTT)
xIn = xInTT(:);
else
xIn = xInTT;
end
dataType = class(xIn);
signalLength = size(xIn,1);
numChannels = size(xIn,2);
frameSize = 100;
frameOverlapLength = 10;
frameRate = frameSize - frameOverlapLength;
featureMatrix = zeros(0,1,dataType);
numFeatureCols = 0;
numFeatureRows = 0;
frameLimits = zeros(0,2,dataType);
info = struct('Mean',0,'StandardDeviation',0,'PeakValue',0);
for idx = 1:numChannels
if numChannels == 1
xChannel = xIn;
else
xChannel = xIn(:,idx);
end
startIdx = 1;
endIdx = frameSize;
while startIdx <= signalLength
if endIdx > signalLength
break;
end
featureIndex = 1;
xFrame = xChannel(startIdx:endIdx,1);
meanValue = mean(xFrame);
numCurrentFeature = numel(meanValue);
info.Mean = featureIndex;
featureIndex = featureIndex+numCurrentFeature;
standardDeviation = std(xFrame);
numCurrentFeature = numel(standardDeviation);
info.StandardDeviation = featureIndex;
featureIndex = featureIndex+numCurrentFeature;
peakValue = max(abs(xFrame));
info.PeakValue = featureIndex;
featureVector = [meanValue(:);standardDeviation(:);peakValue(:)];
featureMatrix = [featureMatrix;featureVector];
if startIdx == 1
numFeatureCols = size(featureVector,1);
end
if idx == 1
numFeatureRows = numFeatureRows+1;
frameLimits = [frameLimits;[startIdx endIdx]];
end
startIdx = startIdx+frameRate;
endIdx = startIdx+frameSize-1;
end
end
tempFeatureMatrix = reshape(featureMatrix,numFeatureCols,numFeatureRows,numChannels);
features = permute(tempFeatureMatrix,[2,1,3]);
end