**- DSP log - http://www.dsplog.com -**

Gray code to Binary conversion for PSK and PAM

Posted By __Krishna Sankar__ On May 12, 2008 @ 5:47 am In __Modulation__ | __18 Comments__

Given that we have discussed Binary to Gray code conversion ^{[1]}, let us discuss the Gray to BInary conversion.

Let be the equivalent Gray code for an bit binary number with representing the index of the bit.

**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 Binary number is the exclusive-OR (XOR) of of the bit of the Gray code and of the bit of the binary number.

**Look Up Table based Matlab/Octave mode for Gray to Binary conversion**

clear

% binary to gray code conversion

ipBin = [0:15] ; % decimal equivalent for a 4-bit binary

opGray = bitxor(ipBin,floor(ipBin/2))

% Gray to Binary conversion

[tt ind] = sort(opGray); % sorting Gray code elements to form the lookup table

opBin = ind(opGray+1)-1; % picking elements from the array

**The Trick from DSP-Guru to do Gray to Binary ^{[2]} conversion ^{[2]}, thanks to Jerry Avins ^{[3]}.**

clear

% binary to Gray code

ipBin = [0:15]

opGray = bitxor(ipBin,floor(ipBin/2))

% Gray code to binary

opBin = bitxor(opGray,floor(opGray/2^8)) ;

opBin = bitxor(opBin,floor(opBin/2^4)) ;

opBin = bitxor(opBin,floor(opBin/2^2)) ;

opBin = bitxor(opBin,floor(opBin/2^1)) ;

1. As on now, I do not understand how the DSP Guru trick ^{[2]} for Gray code to Binary works. Of course, if I figure out, I will update this post.

2. Having discussed Binary to Gray code conversion and Gray to Binary conversion, we are now armed to discuss the bit-error rate probabilities for various modulation schemes (Recall: We have been discussing symbol error rate in Additive White Gaussian noise till date).

Thanks, KrishnaArticle printed from DSP log: **http://www.dsplog.com**

URL to article: **http://www.dsplog.com/2008/05/12/gray-code-to-binary-conversion-for-psk-pam/**

URLs in this post:

[1] Binary to Gray code conversion: **http://www.dsplog.com/2008/05/11/binary-to-gray-code-conversion-psk-pam/**

[2] DSP-Guru to do Gray to Binary: **http://www.dspguru.com/comp.dsp/tricks/alg/grayconv.htm**

[3] Jerry Avins: **http://groups.google.co.in/group/comp.dsp/browse_thread/thread/081ff2279133b4c9#**

[4] click here to SUBSCRIBE : **http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1348583&loc=en_US**

Click here to print.

Copyright © 2007-2012 dspLog.com. All rights reserved. This article may not be reused in any fashion without written permission from http://www.dspLog.com.