Main Content

gray2bin

(Removed) Convert Gray-encoded positive integers to corresponding Gray-decoded integers

gray2bin has been removed. Instead, use the appropriate modulation object or function to remap constellation points. For more information, see Version History.

Description

y = gray2bin(x,modulation,M) generates a Gray-decoded output vector or matrix y with the same dimensions as its input parameter x. x can be a scalar, vector, matrix, or 3-D array. modulation is the modulation type and must be 'qam', 'pam', 'fsk', 'dpsk', or 'psk'. M is the modulation order and must be an integer power of 2.

example

[y,map] = gray2bin(x,modulation,M) generates a Gray-decoded output y with its respective Gray-encoded constellation map, map.

You can use map output to label a Gray-encoded constellation. The map output gives the Gray-encoded labels for the corresponding modulation. See Binary to Gray Symbol Mapping example.

Note

If you are converting binary coded data to Gray-coded data and modulating the result immediately afterwards, you should use the appropriate modulation object or function with the 'Gray' symbol ordering option, instead of gray2bin.

Examples

collapse all

This example shows how to use the bin2gray and gray2bin functions to map integer inputs from binary-coded to a Gray-coded signal constellation and vice versa, assuming 16-QAM modulation. In addition, a visual representation of the difference between Gray-coded and binary-coded symbol mappings is shown.

Create a complete vector of 16-QAM integers. Convert the input vector from binary-code to a Gray-coded mapping using bin2gray. Convert the Gray-encoded symbols, y, back to a binary ordering using gray2bin. Verify that the original data, x, and the final output vector, z, are identical.

M = 16;
x = (0:M-1);
[y,mapy] = bin2gray(x,'qam',M);
z = gray2bin(y,'qam',M);
isequal(x,z)
ans = logical
   1

Show symbol mappings. To create a constellation plot showing the different symbol mappings, use the qammod function to find the complex symbol values. Plot the constellation symbols and label them using the Gray (y) and binary (z) output vectors. The bit vector for the Gray-coded symbols is shown in black and the bit vector for the binary-coded symbols is shown in red. Set the axes scaling so that all points are displayed.

sym = qammod(x,M);
scatterplot(sym,1,0,'b*');
for k = 1:16 
    text(real(sym(k))-0.3,imag(sym(k))+0.3,... 
        dec2base(mapy(k),2,4)); 
    text(real(sym(k))-0.3,imag(sym(k))-0.3,... 
        dec2base(z(k),2,4),'Color',[1 0 0]);
end
axis([-4 4 -4 4])

Scatterplot showing Gray-coded and binary-coded mapping

Input Arguments

collapse all

Gray-encoded input data, specified as a vector or matrix.

Data Types: double

Modulation type, specified as, 'qam', 'pam', 'fsk', 'dpsk', or 'psk'

Modulation order, specified as an integer power of 2.

Data Types: double

Output Arguments

collapse all

Gray-decoded data with the same size and dimensions input x.

Map output to label a Gray-encoded constellation, specified as a vector with a length the size of the modulation order, M. The map gives the Gray-encoded labels for the corresponding modulation.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a

expand all

R2023a: Removed

gray2bin not supported. Instead, use the appropriate modulation object or function to remap constellation points.