2015-11-27 295 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