Skip to content
Snippets Groups Projects
Commit 4a0077ff authored by Eric Kooistra's avatar Eric Kooistra
Browse files

Added TO_UREAL with resolution_w for fixed point unsigned slv conversion to real.

parent 97775d0d
No related branches found
No related tags found
2 merge requests!100Removed text for XSub that is now written in Confluence Subband correlator...,!68Resolve L2SDP-162
......@@ -366,7 +366,8 @@ PACKAGE common_pkg IS
FUNCTION TO_UREAL(uvec : STD_LOGIC_VECTOR) RETURN REAL; -- convert unsigned slv of any length to REAL
FUNCTION TO_SREAL(svec : STD_LOGIC_VECTOR) RETURN REAL; -- convert signed slv of any length to REAL
FUNCTION TO_SREAL(svec : STD_LOGIC_VECTOR; resolution_w : INTEGER) RETURN REAL; -- convert signed fixed point slv of any length, and with fixed point resolution of 2**resolution_w, to REAL
FUNCTION TO_UREAL(uvec : STD_LOGIC_VECTOR; resolution_w : INTEGER) RETURN REAL; -- convert unsigned fixed point slv of any length, and with resolution of 2**resolution_w, to REAL
FUNCTION TO_SREAL(svec : STD_LOGIC_VECTOR; resolution_w : INTEGER) RETURN REAL; -- convert signed fixed point slv of any length, and with resolution of 2**resolution_w, to REAL
-- The RESIZE for SIGNED in IEEE.NUMERIC_STD extends the sign bit or it keeps the sign bit and LS part. This
-- behaviour of preserving the sign bit is less suitable for DSP and not necessary in general. A more
......@@ -1779,17 +1780,28 @@ PACKAGE BODY common_pkg IS
END IF;
END;
FUNCTION TO_UREAL(uvec : STD_LOGIC_VECTOR; resolution_w : INTEGER) RETURN REAL IS
-- First convert as unsigned integer:
VARIABLE v_real : REAL := TO_UREAL(uvec);
BEGIN
-- Then scale to real (see TO_SREAL)
RETURN v_real * 2.0**REAL(resolution_w);
END;
FUNCTION TO_SREAL(svec : STD_LOGIC_VECTOR; resolution_w : INTEGER) RETURN REAL IS
VARIABLE v_real : REAL := TO_SREAL(svec); -- first convert as signed integer
-- First convert as signed integer:
VARIABLE v_real : REAL := TO_SREAL(svec);
BEGIN
-- The resolution_w is the number of bits that LSbit 0 in svec is after or before the fixed point.
-- The real value is then scaled by scaling the integer value by 2**resolution_w:
-- Then scale to real:
-- . The resolution_w is the number of bits that LSbit 0 in svec is after or before the fixed point.
-- . The real value is then scaled by scaling the integer value by 2**resolution_w:
-- . resolution_w = 0 : scale by 2**0 = 1, so no scaling and the value is treated as an integer
-- . resolution_w < 0 : scale up
-- . resolution_w > 0 : scale down
RETURN v_real * 2.0**REAL(resolution_w);
END;
FUNCTION RESIZE_NUM(u : UNSIGNED; w : NATURAL) RETURN UNSIGNED IS
BEGIN
-- left extend with '0' or keep LS part (same as RESIZE for UNSIGNED)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment