1

I would like to plot constellation diagram similar to the figure below. Colorful Constellation.

My approach is something like this

 clc;
 clear all;
 close all;
 N=30000;                            
 M=16;                               
 Sr=randint(N,1,[0,(M-1)]);          
 S=qammod(Sr,16,0,'gray'); S=S(:);   
 Noisy_Data=awgn(S,20,'measured');       % Add AWGN
 figure(2)
 subplot(1,2,1)
 plot(S,'o','markersize',10);
 grid on
 subplot(1,2,2)
 plot(Noisy_Data,'.');
 grid on

May you assist me to make necessary modification to get graph similar to the figure attached above. Thank you.

4

1 回答 1

2

首先要做的是计算数据的二维直方图。这可以通过以下方式完成:

% Size of the histogram matrix
Nx   = 160;
Ny   = 160;

% Choose the bounds of the histogram to match min/max of data samples.
% (you could alternatively use fixed bound, e.g. +/- 4)
ValMaxX = max(real(Noisy_Data));
ValMinX = min(real(Noisy_Data));
ValMaxY = max(imag(Noisy_Data));
ValMinY = min(imag(Noisy_Data));
dX = (ValMaxX-ValMinX)/(Nx-1);
dY = (ValMaxY-ValMinY)/(Ny-1);

% Figure out which bin each data sample fall into
IdxX = 1+floor((real(Noisy_Data)-ValMinX)/dX);
IdxY = 1+floor((imag(Noisy_Data)-ValMinY)/dY);
H = zeros(Ny,Nx);
for i=1:N
  if (IdxX(i) >= 1 && IdxX(i) <= Nx && IdxY(i) >= 1 && IdxY(i) <= Ny)
    % Increment histogram count
    H(IdxY(i),IdxX(i)) = H(IdxY(i),IdxX(i)) + 1;
  end
end

请注意,您可以使用参数NxNy调整所需的绘图分辨率。请记住,直方图越大,数据样本越多(由N模拟参数控制),您需要在直方图箱中拥有足够的数据以避免得到参差不齐的图。

然后,您可以根据此答案将直方图绘制为彩色图。这样做时,您可能希望为直方图的所有非零 bin 添加一个常数,以便为零值 bin 保留白色带。这将提供与散点图更好的相关性。这可以通过以下方式完成:

% Colormap that approximate the sample figures you've posted
map = [1 1 1;0 0 1;0 1 1;1 1 0;1 0 0];

% Boost histogram values greater than zero so they don't fall in the
% white band of the colormap.
S    = size(map,1);
Hmax = max(max(H));
bias = (Hmax-S)/(S-1);
idx = find(H>0);
H(idx) = H(idx) + bias;

% Plot the histogram
pcolor([0:Nx-1]*dX+ValMinX, [0:Ny-1]*dY+ValMinY, H);
shading flat;
colormap(map);

增加到N1000000 后,根据您的样本生成的数据如下图所示:

带有 AWGN 噪声的 16-QAM - 直方图

于 2015-11-29T15:47:13.307 回答