8 How to determine coding of a number from quantization?

8.1 sign magnitude
8.2 ones complement
8.3 offset binary
8.4 2’s complement

Given an analog value say \(x\) and given a maximum absolute possible value to be \(m_{p}\), and given the number of bits available for coding to be \(N\), the following are the algorithm to generate the quantized version of \(x\), called \(\hat {x}\)

8.1 sign magnitude

Input: \(x,m_{p},N\)

output: \(\hat {x}\)

Let \(\Delta =\frac {m_{p}}{2^{N-1}}\) called the step size

Let \(q=round\left [ \frac {abs\left ( x\right ) }{\Delta }\right ] \) which is the quantization level

If \(q\geq 2^{N-1}-1\) then \(q=2^{N-1}\) end if  

if \(x<0\) then \(code=q+2^{N-1}\) else \(code=q\) endif

return \(code\) in base 2

8.2 ones complement

Input: \(x,m_{p},N\)

output: \(\hat {x}\)

Let \(\Delta =\frac {m_{p}}{2^{N-1}}\) called the step size

Let \(q=round\left [ \frac {abs\left ( x\right ) }{\Delta }\right ] \) which is the quantization level

If \(q\geq 2^{N-1}-1\) then \(q=2^{N-1}-1\) end if

If \(x>0\) then \(code=q\) else \(code=\left ( 2^{N}-1\right ) -q\) endif

return \(code\) in base 2

8.3 offset binary

Input: \(x,m_{p},N\)

output: \(\hat {x}\)

Let \(\Delta =\frac {m_{p}}{2^{N-1}}\) called the step size

Let \(q=round\left [ \frac {abs\left ( x\right ) }{\Delta }\right ] \) which is the quantization level

If \(x\geq -\frac {\Delta }{2}\) then

  if \(q\geq 2^{N-1}-1\) then

\(\ \ \ \ \ q=2^{N-1}-1\)

  end if

  \(code=2^{N-1}+q\)

else

  if \(q\geq 2^{N-1}-1\) then

\(\ \ \ \ \ \ q=2^{N-1}\)

  end if

  \(code=2^{N-1}-q\)

end if

return \(code\) in base 2

8.4 2’s complement

Input: \(x,m_{p},N\)

output: \(\hat {x}\)

Let \(\Delta =\frac {m_{p}}{2^{N-1}}\) called the step size

Let \(q=round\left [ \frac {abs\left ( x\right ) }{\Delta }\right ] \) which is the quantization level

If \(x\geq -\frac {\Delta }{2}\) then

  if \(q\geq 2^{N-1}-1\) then

\(\ \ \ \ \ q=2^{N-1}-1\)

  end if

  \(code=q\)

else

  if \(q\geq 2^{N-1}-1\) then

\(\ \ \ \ \ \ q=2^{N-1}\)

  end if

  \(code=2^{N}-q\)

end if

return \(code\) in base 2