Forum Discussion

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

Fixed-point multiplication with "altmult_complex" megafunction

Hi,

I am using the altmult_complex (complex multiplier) with inputs dataa (both real and imaginary) having 16 fractional bits, and inputs datab (both real and imaginary) having 2 decimal bits and 14 fractional bits. Dataa inputs are signed while datab inputs are unsigned.

I know that the output of the megafunction block would be singed results:

-> real = [(dataa_real * datab_real) - (dataa_imag * datab_imag)]

-> imag = [(dataa_real * datab_imag) + (dataa_imag * datab_real)]

Since the multiplication has both decimal and fractional bits, I'd like to know how many bits the outputs would have if I restrict the output to 16-bits in total.

Since 0.16 * 2.14 = 2.30 (32 bits), would restricting output to 16-bits give 2.14? [x.y -> x=decimal bits and y=fractional bits]

Also, would it be better if I use the fixed-point vhdl package?

Appreciate your help and guidance.

15 Replies

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

    --- Quote Start ---

    Since 0.16 * 2.14 = 2.30 (32 bits), would restricting output to 16-bits give 2.14? [x.y -> x=decimal bits and y=fractional bits]

    --- Quote End ---

    altmult_complex knows nothing about fixed point, as you may have noticed.

    Restricting it's output it will give you the 16 less significant bits, which is not what you want.

    Instead, you can either

    a) use altmult_complex with a 32 bit output and then just select the 16 MSBs.

    b) use VHDL's complex package

    c) do it by hand in VHDL

    Any way is a good way.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The product of two 0.16 signed numbers is normally 1.31 in fixed point, I would expect the same shift to take place with altmult_complex, as long as no saturation logic is applied to the result. You may want to keep 17 bits and perform the saturation logic - a result with the MSB set has to be replaced by the most negative value, otherwise, the MSB can be cut.

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

    Thank you very much for numerically detailing out my post/question.

    My main concern is that if I use the previously mentioned inputs into the altmult_complex megafunction block and keep the output bits restricted to 16-bits, would the outputs be 16 MSB, which would include the 2 integer bits (exactly from input datab) and 14 fractional bits by discarding the remaining 16 fractional bits?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    If I understand well you have:

    dataa on 16 bit in 2's complement fractional bit.

    Your maximum dataa value is:

    .0111_1111_1111_1111 = 0.25 - 2^(-16) = MaxA

    Your minimum dataa value is:

    .1000_0000_0000_0000 = -0.5 = MinA

    datab on 16 bit unsigned with 14 fractional bit.

    Your maximum dataa value is:

    11.11_1111_1111_1111 = 4 - 2^(-14) = MaxB

    Your minimum dataa value is:

    00.00_0000_0000_0000 = 0 = MinB

    Now you need to calculate the range of your output.

    The maximum value is:

    2*MaxA*MaxB = 2 - something small

    The minimum value is:

    -2 + something small

    I guess that your output mustb be 2's complement with 2 integer bit and 14 fractional bit whose range is:

    10.00_0000_0000_0000 = -2

    01.11_1111_1111_1111 = 2 - 2^(-14)

    Please check if my calculations are correct. I made them very fast.

    Was this your question?