Create a tunable surface that represents a scalar gain with a bilinear dependence on two scheduling variables. Suppose that the scheduling variables are alpha
, ranging from 0-15 degrees, and V
, ranging from 300-600 m/s. The tunable surface covers a linearly spaced grid in this operating range.
Usually, you use GS0
to parameterize a scheduled gain and tune the surface coefficients with systune. For this example, instead of tuning, manually set the coefficients to non-zero values.
Generate MATLAB code that computes the scalar gain as a function of scheduling variables.
code =
'function Gain_ = fcn(alpha_,V_)
%#codegen
% Type casting
ZERO = zeros(1,1,'like',alpha_+V_);
alpha_ = cast(alpha_,'like',ZERO);
V_ = cast(V_,'like',ZERO);
% Tuned gain surface coefficients
Coeffs = cast([100 28 40 10],'like',ZERO);
Offsets = cast([7.5 450],'like',ZERO);
Scalings = cast([7.5 150],'like',ZERO);
% Normalization
alpha_ = (alpha_ - Offsets(1))/Scalings(1);
V_ = (V_ - Offsets(2))/Scalings(2);
% Compute weighted sum of terms
Y = [ alpha_ , V_ , alpha_*V_ ];
Gain_ = Coeffs(1);
for i=1:numel(Y)
Gain_ = Gain_ + Coeffs(i+1) * Y(i);
end
'
The resulting code is a function, fcn
, that takes two scheduling variables and returns a scalar gain. The function includes the %#codegen
directive, so that it can be used for further code generation, such as implementing a tuned gain schedule in hardware.
The function includes four sections. The first section ensures that the scheduling variables are cast to the same type. The second section encodes the gain coefficients and the offsets and scalings that the software extracts from GS
. These values are hard-coded into fcn
, which can compute the gain surface without reference to GS
. The third section uses these values to compute the normalized scheduling variables. (See tunableSurface
for more information about normalization.)
The last section computes the gain by summing up all the terms in the polynomial expression for the gain surface.