In this post, let us try to understand Gray codes and their usage in digital communication. Quoting from Wiki entry on Gray code [Gray-Wiki],
In a digital communication system, if the constellation symbols are Gray encoded, then the bit pattern representing the adjacent constellation symbols differ by only one bit. We will show in another post that having this encoding structure gives a lesser probability of error than the ‘natural binary ordering’. However, in this post, let us try to figure out the conversion of natural binary representation to Gray code.
Conversion from natural Binary to Gray code
Consider a bit binary number with representing the index of the binary number. Let be the equivalent Gray code.
1. For ,
i.e, the most significant bit (MSB) of the Gray code is same as the MSB of original binary number.
2. For ,
i.e, bit of the Gray code is the exclusive-OR (XOR) of of the bit of the binary number and of the bit of the binary number.
Simple Matlab/Octave code for doing the binary to Gray code conversion
ip = [0:15]; % decimal equivalent of a four bit binary word
op = bitxor(ip,floor(ip/2)); % decimal equivalent of the equivalent four bit gray word
Table : Natural Binary to Gray code
1. As can be seen from the Table above, each row differs from the row above and below by only one bit. Further, just to highlight that this behavior is indeed true for 16th row  and the 1st row  .
2. The conversion shown in the Table above can be used for general modulation schemes like M-PSK (Phase Shift Keying), M-PAM (Pulse Amplitude Modulation) etc.
3. However, for a general M-QAM modulation the binary to Gray code conversion is bit more complicated (and I need to figure that out). We will discuss the QAM case in a future post.Thanks, Krishna
D id you like this article? Make sure that you do not miss a new article by subscribing to RSS feed OR subscribing to e-mail newsletter. Note: Subscribing via e-mail entitles you to download the free e-Book on BER of BPSK/QPSK/16QAM/16PSK in AWGN.