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}\)
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
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
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
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