Generating a Variable-Size Signal - 2020.2 English

Model Composer and System Generator User Guide (UG1483)

Document ID
UG1483
Release Date
2020-11-18
Version
2020.2 English

As discussed in Run-Time Parameter Specification, parameters passed to the kernel can be changed at any time by the host processor or other AI Engines. The default behavior for an input run-time parameter is synchronous. This means for a kernel to fire, a write to the input parameter should take place. Input kernel parameters can also be set asynchronously. In this case, when a write to the input paramter takes place, the value is observed on the next and any subsequent kernel firings until a new write to the input parameter takes place. Run-time parameters can be modeled as variable size signals in Simulink. One way to accomplish this is to create a special structure in MATLAB and use the From Workspace block to import that structure into Simulink. The example below creates the special structure in MATLAB for the case of a real-time parameter vector that has a valid vector value only at time zero.

% Input read from file input.txt and stored in
% stored in MATLAB base workspace as variable "coeffs"
 
data = int32(load('./input.txt'));
assignin('base','coeffs', data);
 
% Creating variable size signals for RTP input
% having values only at time zero
 
coeffs_length = length(coeffs);
signal = struct("dimensions",coeffs_length, ...
                "valueDimensions",[coeffs_length,0]',...
                "values",[coeffs(:).'; zeros(1,coeffs_length)]);
rtp_in = struct("time",[0;1],"signals",signal);

As shown in the previous code block, a nested structure is defined to model the variable signal rtp_in with a valid value only at time zero and no values for sample time one and beyond. This structure can be imported into Simulink using the From Workspace block. If you run the simulation in steps, you can observe the output only at T=0 (as shown in the following figure). For subsequent simulation steps, you see a blank output in the display block.

Figure 1. From Workspace Block
Important: Although the signal type is variable-size, the Simulink dimension on the signal does not reflect the change in size and it always shows the maximum signal size that variable can hold.