Main Content

HDL Reciprocal

Calculate reciprocal with Newton-Raphson approximation method

  • HDL Reciprocal block

Libraries:
Simulink Extras / Additional Math

Description

The HDL Reciprocal block uses the Newton-Raphson iterative method to compute the reciprocal of the block input. The Newton-Raphson method uses linear approximation to successively find better approximations to the roots of a real-valued function.

The reciprocal of a real number a is defined as a zero of the function:

f(x)=1xa.

HDL Coder™ chooses an initial estimate in the range 0<x0<2a as this is the domain of convergence for the function.

To successively compute the roots of the function, specify the Number of iterations parameter. The process is repeated as:

xi+1=xif(xi)f'(xi)=xi+(xiaxi2)=xi.(2axi)

f'(x) is the derivative of the function f(x).

This table shows a comparison of simulation behavior of the HDL Reciprocal block with the Math Reciprocal block:

Math ReciprocalHDL Reciprocal

Computes the reciprocal as 1/N by using the HDL divide operator (/) to implement the division.

Uses the Newton-Raphson iterative method. The block computes an approximate value of reciprocal of the block input and can yield different simulation results compared to the Math Reciprocal block.

To match the simulation results with the Math Reciprocal block, increase the number of iterations for the HDL Reciprocal block.

Ports

Input

expand all

Number to be reciprocated, specified as a bit width between 2 and 128.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Output

expand all

Reciprocal of input, returned as a real scalar. The data type of the output value depends on the input value data type.

Input data typeOutput data type
doubledouble
singlesingle
built-in integerbuilt-in integer
built-in fixed-pointbuilt-in fixed-point

fi (value, 0, word_length, fraction_length)

fi (value, 0, word_length, word_lengthfraction_length–1)

fi (value, 1, word_length, fraction_length)

fi (value, 1, word_length, word_lengthfraction_length–2)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

Parameters

expand all

Number of Newton-Raphson iterations, specified as a scalar.

Programmatic Use

Block Parameter: NumberOfIterations
Type: character vector
Values: scalar
Default: '3'

Block Characteristics

Data Types

double | fixed point | integer | single

Direct Feedthrough

no

Multidimensional Signals

yes

Variable-Size Signals

yes

Zero-Crossing Detection

no

Extended Capabilities

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

Version History

Introduced in R2014b

expand all