Number of integer bits needed for fixed-point inner product




innerprodintbits(a,b) computes the minimum number of integer bits necessary in the inner product of a'*b to guarantee that no overflows occur and to preserve best precision.

  • a and b are fi vectors.

  • The values of a are known.

  • Only the numeric type of b is relevant. The values of b are ignored.


The primary use of this function is to determine the number of integer bits necessary in the output Y of an FIR filter that computes the inner product between constant coefficient row vector B and state column vector Z. For example,

      for k=1:length(X);
        Z = [X(k);Z(1:end-1)];
        Y(k) = B * Z;

More About

collapse all


In general, an inner product grows log2(n) bits for vectors of length n. However, in the case of this function the vector a is known and its values do not change. This knowledge is used to compute the smallest number of integer bits that are necessary in the output to guarantee that no overflow will occur.

The largest gain occurs when the vector b has the same sign as the constant vector a. Therefore, the largest gain due to the vector a is a*sign(a'), which is equal to sum(abs(a)).

The overall number of integer bits necessary to guarantee that no overflow occurs in the inner product is computed by:

n = ceil(log2(sum(abs(a)))) + number of integer bits in b + 1 sign bit

The extra sign bit is only added if both a and b are signed and b attains its minimum. This prevents overflow in the event of (-1)*(-1).

Was this topic helpful?