Products & Services Solutions Academia Support User Community Company

Learn more about Communications Toolbox   

bin2gray - Convert positive integers into corresponding Gray-encoded integers

Syntax

y = bin2gray(x,modulation,M)
[y,map] = bin2gray(x,modulation,M)

Description

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

[y,map] = bin2gray(x,modulation,M) generates a Gray-encoded 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 the example below.

Example

 % To Gray encode a vector x with a 16-QAM Gray encoded
 % constellation and return its map, use:
 x=randint(1,100,16);
 [y,map] = bin2gray(x,'qam',16);
 % Obtain the symbols for 16-QAM
 hMod = modem.qammod('M', 16);
 symbols = hMod.Constellation;
 % Plot the constellation
 scatterplot(symbols);
 set(get(gca,'Children'),'Marker','d','MarkerFaceColor',...
 'auto'); hold on;
 % Label the constellation points according
 % to the Gray mapping
 for jj=1:16
 text(real(symbols(jj))-0.15,imag(symbols(jj))+0.15,...
 dec2base(map(jj),2,4));
 end
 set(gca,'yTick',(-4:2:4),'xTick',(-4:2:4),...
 'XLim',[-4 4],'YLim',...
 [-4 4],'Box','on','YGrid','on', 'XGrid','on');

The example code generates the following plot, which shows the 16 QAM constellation with Gray-encoded labeling.

See Also

gray2bin

  


Free Early Verification Kit

Learn how to apply early verification to your development process through these technical resources.

How much time do you spend on testing to ensure implementation meets system-level requirements?

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS