-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTime_Domain_Features.m
115 lines (94 loc) · 4.64 KB
/
Time_Domain_Features.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
111
112
113
114
115
function [featureTable,outputTable] = Time_Domain_Features(inputData)
%Time_Domain_Features recreates results in Diagnostic Feature Designer.
%
% Input:
% inputData: A table or a cell array of tables/matrices containing the
% data as those imported into the app.
%
% Output:
% featureTable: A table containing all features and condition variables.
% outputTable: A table containing the computation results.
%
% C01.Fault_Code [307 x 1 cell]
% C02.Signal [307 x 1 cell]
%
% This function computes features:
% Signal_stats/Col1_ClearanceFactor
% Signal_stats/Col1_CrestFactor
% Signal_stats/Col1_ImpulseFactor
% Signal_stats/Col1_Kurtosis
% Signal_stats/Col1_Mean
% Signal_stats/Col1_PeakValue
% Signal_stats/Col1_RMS
% Signal_stats/Col1_ShapeFactor
% Signal_stats/Col1_Skewness
% Signal_stats/Col1_Std
%
% Organization of the function:
% 1. Compute signals/spectra/features
% 2. Extract computed features into a table
%
% Modify the function to add or remove data processing, feature generation
% or ranking operations.
%Reference
%[1] Cascales Fulgencio, D.; Quiles Cucarella, E.; García Moreno, E.
%Computation and Statistical Analysis of Bearings’ Time- and
%Frequency-Domain Features Enhanced Using Cepstrum Pre-Whitening: A ML-
%and DL-Based Classification.
%Appl. Sci. 2022.
% Auto-generated by MATLAB. Last revision: 17/09/2022.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create output ensemble.
outputEnsemble = workspaceEnsemble(inputData,'DataVariables',"Signal",'ConditionVariables',"Fault_code");
% Reset the ensemble to read from the beginning of the ensemble.
reset(outputEnsemble);
% Append new signal or feature names to DataVariables.
outputEnsemble.DataVariables = unique([outputEnsemble.DataVariables;"Signal_stats"],'stable');
% Set SelectedVariables to select variables to read from the ensemble.
outputEnsemble.SelectedVariables = "Signal";
% Loop through all ensemble members to read and write data.
while hasdata(outputEnsemble)
% Read one member.
member = read(outputEnsemble);
% Get all input variables.
Signal.Col1 = readMemberData(member,"Signal","Col1");
% Initialize a table to store results.
memberResult = table;
% SignalFeatures
try
% Compute signal features.
inputSignal = Signal.Col1;
Col1_ClearanceFactor = max(abs(inputSignal))/(mean(sqrt(abs(inputSignal)))^2);
Col1_CrestFactor = peak2rms(inputSignal);
Col1_ImpulseFactor = max(abs(inputSignal))/mean(abs(inputSignal));
Col1_Kurtosis = kurtosis(inputSignal);
Col1_Mean = mean(inputSignal,'omitnan');
Col1_PeakValue = max(abs(inputSignal));
Col1_RMS = rms(inputSignal,'omitnan');
Col1_ShapeFactor = rms(inputSignal,'omitnan')/mean(abs(inputSignal),'omitnan');
Col1_Skewness = skewness(inputSignal);
Col1_Std = std(inputSignal,'omitnan');
% Concatenate signal features.
featureValues = [Col1_ClearanceFactor,Col1_CrestFactor,Col1_ImpulseFactor,Col1_Kurtosis,Col1_Mean,Col1_PeakValue,Col1_RMS,Col1_ShapeFactor,Col1_Skewness,Col1_Std];
% Package computed features into a table.
featureNames = ["Col1_ClearanceFactor","Col1_CrestFactor","Col1_ImpulseFactor","Col1_Kurtosis","Col1_Mean","Col1_PeakValue","Col1_RMS","Col1_ShapeFactor","Col1_Skewness","Col1_Std"];
Signal_stats = array2table(featureValues,'VariableNames',featureNames);
catch
% Package computed features into a table.
featureValues = NaN(1,10);
featureNames = ["Col1_ClearanceFactor","Col1_CrestFactor","Col1_ImpulseFactor","Col1_Kurtosis","Col1_Mean","Col1_PeakValue","Col1_RMS","Col1_ShapeFactor","Col1_Skewness","Col1_Std"];
Signal_stats = array2table(featureValues,'VariableNames',featureNames);
end
% Append computed results to the member table.
memberResult = [memberResult, ...
table({Signal_stats},'VariableNames',"Signal_stats")]; %#ok<AGROW>
% Write all the results for the current member to the ensemble.
writeToLastMemberRead(outputEnsemble,memberResult)
end
% Gather all features into a table.
featureTable = readFeatureTable(outputEnsemble);
% Set SelectedVariables to select variables to read from the ensemble.
outputEnsemble.SelectedVariables = unique([outputEnsemble.DataVariables;outputEnsemble.ConditionVariables;outputEnsemble.IndependentVariables],'stable');
% Gather results into a table.
outputTable = readall(outputEnsemble);
end