Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Number Scaling

Hi,

What is the most efficient way to scale numbers into the range of -1, 1 in Verilog using Cyclone II? That is the fastest code with least resources? are there any free IP cores from Altera or others which do so?

I am currently doing it using the NIOS II processor (scaling and casting into fixed point), Is there any hardware solution?

I have downloaded an IP core from IP genious which casts from FP to int, this will do the trick to convert to fixed point and shifting, all that remains now is the scaling??

thanks

11 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    What is the most efficient way to scale numbers into the range of -1, 1 in Verilog using Cyclone II?

    --- Quote End ---

    You do not state the numeric format that you are using.

    The conversion of signed fixed-point B-bit integers to fractional integers is conceptual only, so no conversion is required.

    For example, a 3-bit signed integer has can represent the integer values -4, -3, -2, -1, 0, 1, 2, 3, with 2's compliment binary representation 100b, 101b, 110b, 111b, 001b, 010b, 011b. In fractional integer format, this is a Q2.0 number.

    You can divide this number by 2 to get a Q1.1 representation, i.e., -2.0, -1.5, -1.0, -0.5, 0, 0.5, 1.0, 1.5, or divide by 4 to get a Q0.2 representation, i.e., -1.0, -0.75, -0.50, -0.25, 0.0, 0.25, 0.50, 0.75.

    In all cases, the binary representation is the same (ok, there's a slight difference in that you can put a binary-point between the bits, but that does not exist in the hardware implementation).

    If you want a B-bit number to represent -1.0 to (almost) 1.0, then you just need to interpret it as a Q0.(B-1) fractional integer format number. It will have the range -1.0 to 1.0-1/(2^(B-1)).

    Cheers,

    Dave