-
Notifications
You must be signed in to change notification settings - Fork 0
/
G_FeatureExtraction_Time.m
110 lines (90 loc) · 5.65 KB
/
G_FeatureExtraction_Time.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function timeFeatures = G_FeatureExtraction_Time(signal, fs,...
win, step,numLags,orders,bins,peakNumber,peakNumberEnvelop,peakNumberGradient)
%Check if the signal is two channel
if (size(signal,2)>1)
signal = mean(signal,2);
end
%convert the window and the step to its respective sample numbers
windowLength = round(win * fs);
step = round(step * fs);
%Initialize parameters for Features
subFrames = floor(5/100*windowLength); % 5 percent of the window
% numLags = 2; % for autocorrelation
% orders = 4; % number of orders for moments
% bins = 5; % bins for historgram
% peakNumber = 5; % for peak analysis
% peakNumberEnvelop = 3; % peaks for envelop analysis
% peakNumberGradient = 5;
[featureNames,...
numberOfFeatures,...
envelopFeatureNumber,...
gradientFeatureNumber,...
tachoRPMFeatureNumber,...
slewRateFeatureNumber,...
riseTimeFeatureNumber,...
underShootFeatureNumber,...
dutyCycleFeatureNumber,...
peakAnalysisFeatureNumber,...
fallTimeFeatureNumber] = G_FeatureExtraction_Time_FeatureNames(numLags,orders,bins,peakNumber);
currentPosition = 1; % for tracking signal
L = length(signal);
numberOfFrames = floor((L-windowLength)/step) + 1; %total number of frames
timeFeatures = zeros(numberOfFeatures, numberOfFrames);
Ham = window(@hamming, windowLength); %Hamming window to cut of the end portions
for i=1:numberOfFrames
%current frame
frame = signal(currentPosition:currentPosition+windowLength-1);
frame = frame .* Ham;
if (sum(abs(frame))>eps) %check if there is signal
if (i==1)
framePrev = frame;
end
fnum=1;
timeFeatures(fnum,i) = F_Time_Feature_Energy(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Energy_Entropy(frame, subFrames); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Mean(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Max(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Min(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Median(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Mode(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Peak2Peak(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Peak2RMS(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_RMS(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_RootSumOfSquares(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Skewness(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Std(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Variance(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_ZCR(frame); fnum=fnum+1;
timeFeatures(fnum,i) = F_Time_Feature_Kurtosis(frame); fnum=fnum+1;
timeFeatures(fnum:fnum+dutyCycleFeatureNumber-1,...
i) = F_Time_Feature_DutyCycle(frame, fs ); fnum=fnum+dutyCycleFeatureNumber;
timeFeatures(fnum:fnum+underShootFeatureNumber -1,...
i) = F_Time_Feature_UnderShoot(frame, fs ); fnum=fnum+underShootFeatureNumber;
% timeFeatures(fnum:fnum+tachoRPMFeatureNumber -1,...
% i) = F_Time_Feature_TachoRPM(frame, fs); fnum=fnum+tachoRPMFeatureNumber;
timeFeatures(fnum:fnum+slewRateFeatureNumber-1,...
i) = F_Time_Feature_SlewRate(frame, fs); fnum=fnum+slewRateFeatureNumber;
timeFeatures(fnum:fnum+riseTimeFeatureNumber-1,...
i) = F_Time_Feature_RiseTime(frame, fs); fnum=fnum+riseTimeFeatureNumber;
timeFeatures(fnum:fnum+fallTimeFeatureNumber-1,...
i) = F_Time_Feature_FallTime(frame, fs ); fnum=fnum+fallTimeFeatureNumber;
timeFeatures(fnum:fnum+numLags-1,...
i) = F_Time_Feature_AutoCorrelation(frame,numLags); fnum=fnum+numLags;
timeFeatures(fnum:fnum+orders-1,...
i) = F_Time_Feature_CentralMoment(frame,orders); fnum=fnum+orders;
timeFeatures(fnum:fnum+bins-1,...
i) = F_Time_Feature_Histogram(frame,bins); fnum=fnum+bins;
timeFeatures(fnum:fnum+peakAnalysisFeatureNumber-1,...
i) = F_Time_Feature_PeakAnalysis(frame,peakNumber); fnum=fnum+peakAnalysisFeatureNumber;
% timeFeatures(fnum:fnum+envelopFeatureNumber-1,...
% i) = F_Time_Feature_EnvelopAnalysis(frame,peakNumberEnvelop); fnum=fnum+envelopFeatureNumber;
% timeFeatures(fnum:fnum+gradientFeatureNumber-1,...
% i) = F_Time_Feature_GradientAnalysis(frame,peakNumberGradient);
else
timeFeatures(:,i) = zeros(numberOfFeatures, 1);
end
currentPosition = currentPosition + step;
framePrev = frame;
end
%filter for spurious features
timeFeatures(numberOfFeatures, :) = medfilt1(timeFeatures(numberOfFeatures, :), 3);