【问题标题】:How to plot colorful histogram type constellation diagram in Matlab如何在Matlab中绘制彩色直方图类型的星座图
【发布时间】:2023-03-09 22:19:01
【问题描述】:

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

我的做法是这样的

 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

请您协助我进行必要的修改以获得类似于上图的图形。谢谢你。

【问题讨论】:

    标签: matlab plot signal-processing matlab-figure modulation


    【解决方案1】:

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

    % 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 的颜色图。这样做时,您可能希望向直方图的所有非零 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);
    

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

    【讨论】:

    • 非常感谢您的帮助和解释。需要使用什么颜色规范来获取像附加链接这样的图表。 link 如何设置最佳 $map$ 值 ' = [1 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 36; 222 31 38; 188 35 37; 144 25 27; 124 19 23]/255。没有什么最优化的,只是用了一个绘图程序来读取颜色的 RGB 像素值。
    • 我试图为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); 但它变得一团糟。你能建议我做一些改变吗?谢谢
    • 不确定你会说什么'搞砸',但要保持相同的分辨率,你必须将NxNy加倍,然后相应地增加N以保留垃圾箱计数相似。
    • 非常感谢..可以通过增加直方图矩阵的大小来解决。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-31
    • 1970-01-01
    • 2019-10-16
    • 1970-01-01
    • 2011-06-30
    • 2017-01-27
    • 2011-09-15
    相关资源
    最近更新 更多