Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20707 Discussions

multiplication of two 14bits number

Altera_Forum
Honored Contributor II
1,382 Views

Hi, 

 

i need to multiply two numbers of 14 bits and the result should have the same number of bits, how can i do this?
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
455 Views

 

--- Quote Start ---  

 

i need to multiply two numbers of 14 bits and the result should have the same number of bits, how can i do this? 

--- Quote End ---  

What is your 14-bit number representation? Is it a fractional integer, is it signed, is it unsigned? 

 

You would multiply the two 14-bit numbers and get a 28-bit result. You would then decide which 14-bits to keep. If you discard most-significant-bits, then for numbers that fall outside that range, you need to decide whether to saturate numbers to the most positive or negative 14-bit value. For discarded least-significant-bits, you need to determine how you want to round the number. For a discussion on that, see this thread: 

 

http://www.alteraforum.com/forum/showthread.php?t=29931 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
455 Views

The problem isn't particularly related to FPGA arithmetic and signal processing. I suggest to clarify the intended behaviour by utilizing pencil, paper and a pocket calculator. 

 

P:S.: For the more technical "how can I do", you can either decide for the "big" solution IEEE fixed point package, perform all saturation, truncation and rounding inline in your code (rather inconvenient, I think) or have one or more functions wrapping it.
0 Kudos
Altera_Forum
Honored Contributor II
455 Views

unless you have some special application, then in the perspective of signal processing I would avoid saturation altogether or so since it leads to nonlinearity. However in practice you might consider an occasional clipping if you get the advantage of one extra bit of resolution.  

In particular for discardind one MSB: to multiply two14 bit signed numbers then the maximum positive result is going to be: 

-2^13 * -2^13 = 2^26 i.e. 1 one short of 27 bits  

in other words n bits * n bits requires 2n bits only for the sake of one single case of -2^n-1 * -2^n-1. 

The conclusion is that you can discard 1 MSB with added clipping and discard 13 LSBs. The doubling of gain is the side effect but resolution is maintained. Doing so, you are also forcing partially symmetric swing. 

 

In some other cases, maximum expected values may even allow you discarding more MSBs e.g. when multiplying sin * cos
0 Kudos
Altera_Forum
Honored Contributor II
455 Views

I always suggest to write all these calculations in Excel and try a bit precise calculation beneath a real calculation in comparison. Yes, we "profs" do that in MATLAB, but not everybody has that available:) 

 

You thus can also test rounding and error behaviour for your particular range of numbers easily. ("14 bit" is not 100% of the information about that)
0 Kudos
Reply