Export Feature Extraction Function and Simulink Model for Streaming Data
In Diagnostic Feature Designer, you can generate a MATLAB® function that automates your interactive computations for the features you choose. The function that you generate can be formatted in two ways:
Automate feature extraction from multimember data ensembles, as described in Automatic Feature Extraction Using Generated MATLAB Code.
Automate feature extraction for streaming data.
Generate a MATLAB function that is MATLAB Coder™ compliant and use
codegen
(MATLAB Coder) to convert the function to C/C++.Generate a Simulink® model that uses the MATLAB function.
Spectral features that you create using autoregressive or state-space modeling are not supported for streaming data. To generate code for spectral features, you must use the Welch method to extract them. Features derived from ensemble statistics variables or frame-based processing are also not supported for code generation.
Generate MATLAB Function for Streaming
The following figure shows the ranking table for a set of features. These features include spectral features that were computed using an autoregressive model.
Click Export to access the export options and select
Generate Function for Features
.
The dialog box allows you to choose the number of top ranked features and whether you want to format the function for streaming data.
When you click OK, the app generates the streaming-formatted function. The following code is the descriptive header at the top of the function.
%DIAGNOSTICFEATURES recreates results in Diagnostic Feature Designer. % % Input: % inputData: A timetable. % % Output: % featureTable: A table containing all features. % % This function computes signals: % Vibration_tsa/Data % % This function computes features: % Vibration_sigstats/Mean % Vibration_tsa_rotmac/RMS % Vibration_tsa_rotmac/CrestFactor % % 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. % Auto-generated by MATLAB
For comparison, the exported code description from the same session data, but without streaming format, is provided in Automatic Feature Extraction Using Generated MATLAB Code.
Generate Streaming Code
From this new MATLAB function, you can now generate C or C++ code using codegen
(MATLAB Coder).
For example, if your function has the file name diagnosticFeatures.m
and the representative function inputs are in the timetable tt
, then
generate C code using the following
command.
codegen diagnosticFeatures.m -args {tt}
Export Simulink Block for Streaming Data
In addition to exporting a MATLAB function, you can also export a Simulink block that uses that function.
In the Export menu, select Generate Feature Extraction
Simulink Block
.
The resulting dialog box is similar to the Generate Function for Features dialog box but does not include a checkbox for streaming. This is because the Simulink Block code is always formatted for streaming.
When you click OK, the app generates a template Simulink model that includes blocks for the vibration and tacho signal inputs, the exported Feature Extraction block, and an output scope.
Double-click the Feature Extraction block to open the block parameters and confirm or specify the feature extraction function as well as buffering, independent variable, and sample time and start time information.
Double click an input block to specify the input parameters. The block includes tabs for main parameters and signal attributes.
You can incorporate additional blocks as well such as a Classification Learner Predict block.
See Also
Diagnostic Feature
Designer | MATLAB
Coder (MATLAB Coder) | codegen
(MATLAB Coder) | Classification Learner