Main Content

Generate a MATLAB Function in Diagnostic Feature Designer

In Diagnostic Feature Designer, you explore features interactively, using tools for signal processing, feature generation, and ranking. Once you select the set of the features that perform best, you can generate a MATLAB® function that reproduces the calculations for those features. You can apply this function directly to a larger set of measurement data and increase the number of members in your feature set. You can also modify the function to suit your application, and incorporate part or all of the function into other code.

This example shows how to generate a MATLAB function to compute a set of features, and how to validate that function with the original data set.

The example assumes that you are familiar with ensemble data concepts and with basic operations in the app, such as data import, signal processing, and feature generation. For more information on these concepts and operations, see Design Condition Indicators for Predictive Maintenance Algorithms.

Import the Transmission Model Data

This example uses ensemble data generated from a transmission system model in Using Simulink to Generate Fault Data. Outputs of the model include:

  • Vibration measurements from a sensor monitoring casing vibrations

  • Tachometer sensor, which issues a pulse every time the shaft completes a rotation

  • Fault code indicating the presence of a modeled fault

In your MATLAB command window, load the transmission data, which is stored in the table dataTable.

load dfd_Tutorial dataTable
dataTable is an ensemble table that contains 16 members, each of which represents one simulated transmission system. Each row of the table corresponds to one member. Each column of the table corresponds to one variable, such as Vibration or FaultCode. All ensemble members have the same variables.

Open Diagnostic Feature Designer.

diagnosticFeatureDesigner

In the app, import dataTable. During the import process, set the faultCode type to a condition variable. When the import is complete, the Signals list in the Variables pane displays the vibration and tacho data. For information on the import process, see Import and Visualize Ensemble Data in Diagnostic Feature Designer.

dataTable is selected in the Dataset selection menu on the left. The Variables pane on the right shows the imported variables.

Compute a TSA Signal

Compute a time-synchronous average (TSA) signal from your vibration and tacho signals. To do so, first select Vibration/Data in the Variables pane. Then, in the Feature Designer tab, select Filtering & Averaging > Time-Synchronous Averaging. Set the parameters as shown in the following figure and click OK.

The Time-Synchronous Averaging tab is on the top. The Variables pane is on the bottom.

The new signal appears in the Variables pane.

In the Variables pane, the new signal, Vibration_tsa, is the third signal on the list.

For information on TSA signals, see tsa.

Extract Features from the TSA Signal

In the Variables pane, select the TSA signal. Then, in the Feature Designer tab, select Time-Domain Features > Signal Features to open the set of available signal features. Select the features for Mean, Standard Deviation, and Kurtosis.

The Signal Features tab is on the top. The Statistical Features section, which is the first feature-selection section of the tab, includes the selected features. The Variables pane on the bottom shows that Vibration_tsa is selected.

View the feature values. In the Variables pane, select FeatureTable1. Then, in the plot gallery, click Feature Table View. These steps open a table containing the feature values for each member along with the condition variable faultCode.

Feature value review. In the Variables pane on the left, FeatureTable1 is selected. In the Plot gallery on the right, Feature Table View is the middle plot option. The feature values are on the bottom.

Generate a MATLAB Function

Generate a MATLAB function that reproduces the calculations for these features. In the Feature Designer tab, select Export > Generate Function for Features.

Export Features options. On the top, The Export button is on the far right. Underneath the button is a menu that contains options for Data and Code exports. In the Code section of the menu, Generate Function for Features is the first option and is selected.

Your selection opens a dialog box that allows you to specify the feature table and the features. Because you have performed no ranking, the app configures the dialog box to export all three features.

Generate Function for Features dialog box. The top option is "Feature Table", which is set to FeatureTable1. The middle option is "Features sorted by", and is set to "None". The third option, "Number of Top Features", is disabled. Underneath the options are Help, OK, and Cancel buttons.

When you click OK, a function script opens in the MATLAB editor that begins with the following lines.

function [featureTable,outputTable] = diagnosticFeatures(inputData)
%DIAGNOSTICFEATURES 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.
%
% This function computes signals:
%  Vibration_tsa/Data
%
% This function computes features:
%  Vibration_tsa_sigstats/Kurtosis
%  Vibration_tsa_sigstats/Mean
%  Vibration_tsa_sigstats/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.
The preamble describes what the function computes. In this case, the function computes the features along with the TSA processing that produced the signal source for these features. Save the script as diagnosticFeatures.m.

For more information on the code content, see Anatomy of App-Generated MATLAB Code.

Validate Function with the Original Data

Run the function using dataTable to create a new feature table featuretable.

featuretable = diagnosticFeatures(dataTable)

Compare the first eight feature values to the corresponding feature values in the app. At the level of the displayed precision, the values are identical.

  16×4 table

    faultCode    Vibration_tsa_stats/Kurtosis    Vibration_tsa_stats/Mean    Vibration_tsa_stats/Std
    _________    ____________________________    ________________________    _______________________

        0                   2.2516                       0.022125                    0.99955        
        1                   2.2526                      -0.027311                      0.999        
        1                   2.2571                       -0.45475                    0.99629        
        1                   2.2526                        0.47419                      0.999        
        1                   2.2529                        0.37326                      0.999        
        1                   2.2526                       -0.14185                      0.999        
        1                   2.2529                        0.40644                      0.999        
        1                   2.2529                       -0.47485                    0.99915
       

See Also

| | | | |

Related Topics