Main Content

CORDIC Sigmoid HDL Optimized

CORDIC-based sigmoid activation

Since R2024a

  • CORDIC Sigmoid HDL Optimized block

Libraries:
Fixed-Point Designer HDL Support / Math Operations

Description

The CORDIC Sigmoid HDL Optimized block returns the sigmoid activation of u, computed using a CORDIC-based implementation optimized for HDL code generation.

Examples

expand all

This example demonstrates how to compute the sigmoid activation of a given real-valued set of data using the CORDIC Sigmoid HDL Optimized block.

Algorithm

The sigmoid function is defined by

y=11+exp(-x)

which is equivalent to

y=1-tanh(-x/2)2.

The core algorithm of this block uses the CORDIC algorithm in hyperbolic rotation mode to compute the Hyperbolic Tangent HDL Optimized (tanh).

Supported Data Types

The CORDIC Sigmoid HDL Optimized block supports single, double, binary-point scaled fixed-point, and binary-point scaled-double data types for simulation. However, only binary-point scaled fixed-point data types are supported for HDL code generation.

I/O Interface

The CORDIC Sigmoid HDL Optimized block accepts data when the ready output is high, indicating that the block is ready to begin a new computation. Use validIn to indicate a valid input. If the block successfully registers the input value it will de-assert the ready signal; you must then wait until the signal is asserted again to send a new input. This protocol is summarized in the following wave diagram. Note how the first valid input to the block is discarded because the block was not ready to accept input data.

validIn.png

When the block has finished the computation and is ready to send the output, it will assert validOut for one clock cycle. Then ready will be asserted, indicating that the block is ready to accept a new input value.

validOut.png

Simulate the Model

Open the CORDICSigmoidModel model.

mdl = 'CORDICSigmoidModel';
open_system(mdl)

The model contains the CORDIC Sigmoid HDL Optimized block connected to a data source which takes in an array of inputs and passes an input value from the array to the CORDIC Sigmoid HDL Optimized block when it is ready to accept a new input. The output computed for each value is stored in a workspace variable. The simulation terminates when all inputs have been processed.

Define an array of inputs.

x = fi(linspace(-10,10,100));

Simulate the model.

sim(mdl);

When the simulation is complete, a new workspace variable, sigmoidOutput, is created to hold the computed value for each input.

Plot the Output

Plot the error of the calculation by comparing the output of the CORDIC Sigmoid HDL Optimized block to that of the MATLAB® cordicsigmoid function.

yMATLAB = cordicsigmoid(x);
yMATLAB.numerictype
ans =


          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 14
sigmoidOutput.numerictype
ans =


          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 16
        FractionLength: 14
figure(1);
plot(x, sigmoidOutput);
hold on
plot(x, yMATLAB);
legend('CORDIC Sigmoid HDL Optimized block','cordicsigmoid Function');

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent CORDIC Sigmoid HDL Optimized block, cordicsigmoid Function.

Verify the block output is bit-exact with the output of the cordicsigmoid function.

max(yMATLAB' - sigmoidOutput)
ans = 
     0

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Signed
            WordLength: 17
        FractionLength: 14

Ports

Input

expand all

Input data, specified as a real-valued scalar.

If u is a fixed-point or scaled double data type, u must use binary-point scaling. Slope-bias representation is not supported for fixed-point data types. Only binary-point scaled fixed-point data types are supported for code generation.

Data Types: single | double | fixed point

Whether input is valid, specified as a Boolean scalar. This control signal indicates when the data from the u input port is valid. When this value is 1 (true), the block captures the value on the u input port. When this value is 0 (false), the block ignores the input samples.

Data Types: Boolean

Output

expand all

Sigmoid activation of the value at u, returned as a scalar. The value at y is the CORDIC-based approximation of the sigmoid activation of u.

When the input u is floating point, the output y has the same data type as the input. When the input is a fixed-point data type, the output has the same word length as the input and a fraction length equal to 2 less than the word length.

Data Types: single | double | fixed point

Whether the output data is valid, returned as a Boolean scalar. When the value of this control signal is 1 (true), the block has successfully computed the output y. When this value is 0 (false), the output data is not valid.

Data Types: Boolean

Whether the block is ready, returned as a Boolean scalar. This control signal indicates when the block is ready for new input data. When this value is 1 (true), and the validIn value is 1 (true), the block accepts input data in the next clock cycle. When this value is 0 (false), the block ignores input data in the next clock cycle.

Data Types: Boolean

More About

Algorithms

expand all

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2024a