如何在Matlab中绘制彩色直方图型星座图

如何在Matlab中绘制彩色直方图型星座图,matlab,plot,signal-processing,matlab-figure,modulation,Matlab,Plot,Signal Processing,Matlab Figure,Modulation,我想绘制类似下图的星座图。 . 我的方法是这样的 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'); %

我想绘制类似下图的星座图。 .

我的方法是这样的

 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

请您协助我进行必要的修改,以获得与上图类似的图表。多谢各位

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

% 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
N
增加到1000000后,根据您的样本生成的数据将显示以下曲线图:


非常感谢您的帮助和解释。需要使用什么颜色规范才能获得像所附链接一样的图形。如何设置最佳$map$值“=[1 1;0 0 1;0 1 1;1 1 0;1 0 0]”。谢谢链接中的一个看起来像是
[39 35 94;61 97 173;107 203 227;159 207 98;248 238 27;245 131 34;236 36;222 31 38;188 35 37;144 25 27;124 19 23]/255
。没有什么优化,只是用一个绘图程序读取颜色的RGB像素值;S=S(:)因此我更改了代码
ValMaxX=8;ValMinX=-8;ValMaxY=8;ValMinY=-8;dX=(ValMaxX ValMinX)/(Nx-1);dY=(ValMaxY-ValMinY)/(Ny-1)但它正在变得一团糟。你能给我一些建议吗。谢谢您不确定您会称之为“混乱”,但要保持相同的分辨率,您必须加倍
Nx
Ny
,然后相应地增加
N
,以保持垃圾箱计数相似。非常感谢。。可以通过增加直方图矩阵的大小来解决。
% 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);