| Communications Toolbox | ![]() |
The example in the previous section created a scatter plot from the modulated signal. Although the plot showed the points in the QAM constellation, the plot did not indicate which integers between 0 and 15 the modulator mapped to a given constellation point. This section addresses the following problem:
Problem Plot a 16-QAM signal constellation with annotations that indicate the mapping from integers to constellation points. |
The solution uses the scatterplot function to create the plot and the text function in MATLAB to create the annotations.
To view a completed M-file for this example, enter edit commdoc_const in the MATLAB Command Window.
1. Find All Points in the 16-QAM Signal Constellation. Applying the qammod function to a vector of integers between 0 and 15 results in an output vector containing all points in the 16-QAM signal constellation.
M = 16; % Number of points in constellation intg = [0:M-1].'; % Vector of integers between 0 and M-1 pt = qammod(intg,M); % Vector of all points in constellation
2. Plot the Signal Constellation. The scatterplot function plots the points in pt.
% Plot the constellation. scatterplot(pt);

3. Annotate the Plot to Indicate the Mapping. To annotate the plot to show the relationship between intg and pt, use the text function to place a number in the plot beside each constellation point. The coordinates of the annotation are near the real and imaginary parts of the constellation point, but slightly offset to avoid overlap. The text of the annotation comes from the binary representation of intg. (The dec2bin function in MATLAB produces a string of digit characters, while the de2bi function used in the last section produces a vector of numbers.)
% Include text annotations that number the points. text(real(pt)+0.1,imag(pt),dec2bin(intg)); axis([-4 4 -4 4]); % Change axis so all labels fit in plot.
Binary-Coded 16-QAM Signal Constellation

In the plot above, notice that 0001 and 0010 correspond to adjacent constellation points on the left side of the diagram. Because these binary representations differ by two bits, the adjacency indicates that qammod did not use a Gray-coded signal constellation. (That is, if it were a Gray-coded signal constellation, then the annotations for each pair of adjacent points would differ by one bit.)
By contrast, the constellation below is one example of a Gray-coded 16-QAM signal constellation.
Gray-Coded 16-QAM Signal Constellation

The only difference, compared to the previous example, is that you pass in 'grey' as the symbol order argument to the qammod function.
%% Modified Plot, With Gray Coding M = 16; % Number of points in constellation intg = [0:M-1].'; pt = qammod(intg,M,[],'gray'); % Vector of all points in constellation scatterplot(pt); % Plot the constellation. % Include text annotations that number the points. text(real(pt)+0.1,imag(pt),dec2bin(intg)); axis([-4 4 -4 4]); % Change axis so all labels fit in plot.
| Modulating a Random Signal | Pulse Shaping Using a Raised Cosine Filter | ![]() |
© 1994-2005 The MathWorks, Inc.