2015-11-27 85 views
1

我想绘制类似于下图的星座图。 Colorful Constellation如何在Matlab中绘制彩色直方图类型星座图

我的做法是这样

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 

愿你帮助我作出必要的修改,以获得图形类似于上面附着的身影。谢谢。

回答

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控制),您需要在直方图区域中有足够的数据以避免出现斑点图。

然后,您可以根据this answer将柱状图绘制为彩色地图。这样做时,您可能会希望为直方图的所有非零分箱添加一个常量,以便将白色波段保留为零值分箱。这将提供与散点图更好的相关性。这是可以做到的:

% 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); 

增加N 1000000后,这给根据您的样品产生的数据如下情节:

16-QAM with AWGN noise - histogram plot

+0

非常感谢您的帮助和解释。需要使用什么颜色规范来获取附加链接等图形。 [link](http://www.nature.com/nphoton/journal/v7/n7/images/nphoton.2013.109-f4.jpg)如何设置最优$ map $ value'= [1 1 1; 0 0 1 ; 0 1 1; 1 1 0; 1 0 0]'。谢谢你 – salmannsu

+0

从链接的一个看起来像'[39 35 94; 61 97 173; 107 203 227; 159 207 98; 248 238 27; 245 131 34; 236 36 36; 222 31 38; 188 35 37; 144 25 27; 124 19 23]/255'。没有什么最佳的,只需要一个绘画程序来读取颜色的RGB像素值。 – SleuthEye

+0

我试图得到'S = qammod(Sr,64,0,'gray')的相同图。 S = S(:);'因此我改变了代码'ValMaxX = 8; ValMinX = -8; ValMaxY = 8; ValMinY = -8; dX =(ValMaxX-ValMinX)/(Nx-1); dY =(ValMaxY-ValMinY)/(Ny-1);'但它正在变得混乱。你可以提出一些改变吗?谢谢 – salmannsu