1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.40 out of 5)
Loading ... Loading ...
Print Print

Binary to Gray code for 16QAM

by Krishna Sankar on June 1, 2008

In the previous post on Binary to Gray code conversion for PSK, I had claimed that “for a general M-QAM modulation the binary to Gray code conversion is bit more complicated“. However following a closer look, I realize that this is not so complicated. :)

The QAM scenario can be treated as independent PAM modulation on I arm and Q-arm respectively. For example, let us consider 16-QAM scenario.

Each constellation point can represent bits, with two bits on the I axis and two on the Q axis. For 16-QAM, the values taken by the I and Q axes are {-3, -1, +1, +3}. The two bits on the I and Q arm can be Gray coded as shown in the table below

b0b1 I b2b3 Q
00 -3 00 -3
01 -1 01 -1
11 +1 11 +1
10 +3 10 +3

Table: Gray coded constellation mapping for 16-QAM

The constellation diagram with the bit mapping is shown below.

16QAM modulation with Gray coded mapping

Figure: 16QAM constellation with Gray coded mapping

As can be observed from the figure above, the adjacent constellation symbols differ by only one bit. As simple as that. :)

Simulation model for Binary to Gray coded mapping for 16-QAM

% Matlab/Octave code for converting bits into 16-QAM constellation

clear all
M = 16;
% number of constellation points
k = log2(M); % number of bits in each constellation
% defining the real and imaginary PAM constellation
% for 16-QAM
alphaRe = [-(2*sqrt(M)/2-1):2:-1 1:2:2*sqrt(M)/2-1];
alphaIm = [-(2*sqrt(M)/2-1):2:-1 1:2:2*sqrt(M)/2-1];
% input - decimal equivalent of all combinations with b0b1b2b3
ip = [0:15];
ipBin = dec2bin(ip.'); % decimal to binary
% taking b0b1 for real
ipDecRe = bin2dec(ipBin(:,[1:k/2]));
ipGrayDecRe = bitxor(ipDecRe,floor(ipDecRe/2));
% taking b2b3 for imaginary
ipDecIm = bin2dec(ipBin(:,[k/2+1:k]));
ipGrayDecIm = bitxor(ipDecIm,floor(ipDecIm/2));
% mapping the Gray coded symbols into constellation
modRe = alphaRe(ipGrayDecRe+1);
modIm = alphaIm(ipGrayDecIm+1);
% complex constellation
mod = modRe + j*modIm;


The above code snippet works only for 4QAM and 16QAM.

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.

{ 13 comments… read them below or add one }

imene May 14, 2012 at 1:27 pm

krishna please answer me if you have the response .


Avatar of Krishna Sankar Krishna Sankar May 15, 2012 at 5:47 am

@imene: plz see above


imene May 8, 2012 at 4:47 pm

I found your mail in site mathworks, so I decided to contact you to request information please.

I am a student at the University of Poitiers in France,
I work on a topic of digital communication (BICM-ID and image transmission) first offers but I have to implement a digital transmission channel,
first time I have a code BICM (Bit Interleaved Coded Modulation) with a Viterbi decoder I want to do with a MAP decoder, the MAP so I did it but with BPSK modulation and now I want to do this with 16QAM but I can not do the demapping and calculation of LLRs 4.

if you can guide me or direct me please Mr. krishna
and if you want me to send you the code to see.
thank you in advance for your understanding and I expect a reply from you with impatience.


Avatar of Krishna Sankar Krishna Sankar May 15, 2012 at 5:35 am

@imene: the post on softbit for 16qam might be of help


shreya March 14, 2013 at 7:46 pm

i need your help…can i have your email id????


Avatar of Krishna Sankar Krishna Sankar March 15, 2013 at 5:23 am

@shreya: you can use the comments section. my email id is listed in http://www.dsplog.com/about/


imene May 7, 2012 at 4:15 pm

SALUT tt le monde
SVP je suis dans un cas délécat
vous connaissez comment faire le décodage map mais avec 16QAM
je l’ai mé avec BPSK
merci de me répondre ds les bref délai


Avatar of Krishna Sankar Krishna Sankar May 8, 2012 at 5:34 am

@imene: Thanks, but I can’t read French :)


ghadiya hitesh April 20, 2012 at 6:26 am

hello you have done great job.
I want code of 16 qammod and demodulatio to see the effect of carrier offset in it.
As inbuild code dose not allow to pass me frequency so i can’t do it.
If you have specific code for 16 qammod and demod then sent me.


Avatar of Krishna Sankar Krishna Sankar April 23, 2012 at 5:22 am

@ghadiya: Hmm..no, I do not have the qammod() function


pi March 2, 2010 at 5:41 pm

how about for demodulator?


Avatar of Krishna Sankar Krishna Sankar March 30, 2010 at 4:37 am

@pi: BER for 16QAM with Gray coding is discussed in http://www.dsplog.com/2008/06/05/16qam-bit-error-gray-mapping/


Reeda January 22, 2010 at 9:36 am

How about 8QAM Bit Error Rate (BER) with Gray mapping????


Leave a Comment

Previous post:

Next post: