Main Content

Protect Circuit Envelope Model

This example shows how to use Simulink Coder™ model protection with an RF Blockset™ circuit envelope model so that it can be shared as an SLXP file with a third party without revealing implementation details and intellectual property.

Model Protection Overview

You can configure the protected model to allow end users to perform only a specific subset of tasks, such as viewing and simulation. In addition, you can optionally password protect each option with AES-256 encryption. For example, you can enable third party end users to simulate the protected model without a password, and you can protect the ability to open a read-only web view of the model with a password to conceal the implementation details. Meanwhile, when you share the same protected model with your internal team collaborators, you can also provide them the password to allow them to see and inspect the implementation details too. Furthermore, you can create a harness model that references the protected model. End users can use this harness model along with the interface report to understand how to use the protected model and how to interface it with their existing systems. For more information, see Protect Models to Conceal Contents (Simulink Coder).

Create Protected Model for Simulation and Password-Protected Viewing

Protect the model of an RF direct-conversion receiver (DCR) configured for use within an automatic gain control (AGC) loop. Note that all parameters of blocks from the Circuit Envelope library are nontunable block parameters, whose values cannot change during simulation. Consequently, none of the parameters of blocks within the RF network can be designated as tunable parameters of the protected model. However, the VGA block and Variable Attenuator block accept Simulink® signal controls, and these are root-level input signals to the model. Furthermore, the IIP2 and IIP3 values of the VGA block are controlled by Constant block sources in the model, whose parameters are tunable. For more information, see Tune and Experiment with Block Parameter Values.

Specify amplifier nonlinearities for the VGA blocks. These are tunable parameters for the model.

vgaIIP2 = 50;
vgaIIP3 = 30;

Specify mixer impairments for the IQ Demodulator block. These are nontunable parameters for the model.

mixerParameters.LOToRFIsolation = 105;
mixerParameters.PhaseNoiseFrequencyOffsets = 1e6*[0.2 1 2 3 7];
mixerParameters.PhaseNoiseLevels = [-70 -80 -95 -110 -120];
mixerParameters.IIP2 = 55;
mixerParameters.CSFilterPassBandEdgeFrequency = 50e6;

Open the model of the DCR.

mdl = 'RFDCR';
open_system(mdl)

You can protect the model interactively or programmatically; both approaches are illustrated here. In this example, protect the model such that end users can simulate it without a password and open a read-only web view with the password. In addition, automatically generate a test harness model that provides an isolated environment to test the protected model. Note that Simulink Coder is required to create the protected model, while Simulink Report Generator™ is required to generate the web view. Alternatively, if you do not have Simulink Report Generator, then you can still create a protected model enabled only for simulation.

In either case, temporarily suppress the warning regarding non-passivity of noise correlation data derived from the rational fit of the S-parameters. This consideration is specific to this model and S2P file.

warningState(1) = warning('off', ...
    'simrf:simrfV2errors:DerivedNoiseNotPassive');
restoreWarningState(1) = onCleanup(@()warning(warningState(1)));

To interactively create a protected model, use the Protected Model Creator (Simulink Coder). On the Simulink Toolstrip Simulation tab, click the Save button arrow, and then select Protected Model. For this example, set these options in the Protected Model Creator:

  • If you have a Simulink Report Generator license, select Read-only view. In this example, set the password as RF Blockset for the read-only view.

  • On the Simulation Options tab, click Refresh. Then, select both parameters as tunable.

  • On the Save Options tab, clear Package protected model with dependencies in a project. Select Create harness model for protected model.

To programmatically create a protected model, use the Simulink.ModelReference.protect (Simulink Coder) function. Prior to calling this function, optionally specify passwords for the various functionalities of the protected model that you intend to enable. In this example, set the password as RF Blockset for the read-only view, and suppress the warning regarding the omission of password protection for simulation of the protected model. In addition, if you have a Simulink Report Generator license, set generateWebView to true in the following code.

warningState(2) = warning('off', ...
    'Simulink:protectedModel:EncryptOnNoPasswordForCategory');
restoreWarningState(2) = onCleanup(@()warning(warningState(2)));

generateWebView = false; % Requires Simulink Report Generator
Simulink.ModelReference.ProtectedModel.setPasswordForView(...
    mdl,'RF Blockset')
[~] = Simulink.ModelReference.protect(mdl,...
    Harness=true,WebView=generateWebView,Encrypt=true,Report=true,...
    TunableParameters={'vgaIIP2','vgaIIP3'});
Creating protected model for 'RFDCR'.
### Searching for referenced models in model 'RFDCR'.
### Found 1 model reference targets to update.
### Starting serial model reference simulation build.
### Generating code for Physical Networks associated with solver block 'RFDCR/Configuration/Solver Configuration' ...
done.
### Successfully updated the model reference simulation target for: RFDCR
Finished creating protected model '/tmp/Bdoc24b_2679053_1051562/tp434937b9/simrf-ex17815065/RFDCR.slxp'.
Creating harness model for protected model 'RFDCR.slxp'.
### Searching for referenced models in model 'RFDCR_harness'.
### Found 0 model reference targets to update.
Finished creating harness model '/tmp/Bdoc24b_2679053_1051562/tp434937b9/simrf-ex17815065/RFDCR_harness.slx'.

Revert the temporary warning suppression to restore the warning states.

clear restoreWarningState

Examine Protected Model Interface Report

View the protected model interface report, which you can use as a reference to communicate with the end users of your protected model. To open the report interactively, you can right-click on the newly created SLXP file in the Current Folder browser and select Open Report. To open the report programmatically, execute the following MATLAB command.

Simulink.ProtectedModel.open('RFDCR','report')

Select the Summary subpage to view details about the environment, platform, and version information, as well as the model functionality supported by the protected model.

Select the Interface Report subpage to view details such as the input and output specifications and tunable parameters associated with the model.

Examine Protected Model Read-Only Web View

If available, open the read-only web view of the protected model. If applicable, enter the password in the respective dialog prompt. In this example, the password for the read-only view is RF Blockset. Note that Simulink Report Generator is not required to open the web view, but it is required to generate it. To open the read-only view interactively, you can right-click on the newly created SLXP file in the Current Folder browser and select Open Webview. To open the read-only view programmatically, execute the following MATLAB command.

Simulink.ProtectedModel.open('RFDCR','webview')

Test Protected Model Using Harness

Execute the following MATLAB command to simulate the test harness model. Note that no password is required for simulation in this example.

sim RFDCR_harness