- 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 , let us discuss the Gray to BInary conversion.

## Conversion from Gray code to natural Binary

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.

## Simulation model

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  conversion , thanks to Jerry Avins .
``` 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)) ;```

## Concluding thoughts

1. As on now, I do not understand how the DSP Guru trick  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,
Krishna

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

URLs in this post:

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

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