sq64qam_gray_map.m

来自「一些关于调指和解调的小程序」· M 代码 · 共 110 行

M
110
字号
function out=sq64QAM_Gray_map(input)

%%%------example--------------------
%%% input=[0 1 1 0 1 1 0 1 1 0 0 1]
%%% out=[3+3j
%%%      5+3j]


%%%将输入的信息比特流映射为方形64QAM星座点;输出为并行序列,为表示星座点的复数
%%%输入序列长度应为6的倍数;每6个比特映射为一个星座点

%%% 'input' is the inputed source bit sequence
%%% 'output' is the mapped constellations, and is  a parallel sequence

K=length(input)/6;    %%% The number of symbols
d=1/sqrt(42);                  %%% The minimum distance between constellations is 2*d
x=[7*d,5*d,3*d,d,-d,-3*d,-5*d,-7*d];    %%% coordinate matrix
y=[7*d,5*d,3*d,d,-d,-3*d,-5*d,-7*d]; 

for i=1:K             %%%将input变成K×6的矩阵,便于映射处理,每一行对应一个星座点
    for k=1:6
        temp(i,k)=input(6*(i-1)+k);
    end
end

%%% mapping --------------------------------
%%% Y-coordinate ---------------------------%%% 6个比特中的前三位决定纵坐标,后三位决定横坐标
for i=1:K
    if [temp(i,1),temp(i,2),temp(i,3)]==[0,0,0]
        max(i,2)=y(1);
    end
    
    if [temp(i,1),temp(i,2),temp(i,3)]==[0,0,1]
        max(i,2)=y(2);
    end
    
    if [temp(i,1),temp(i,2),temp(i,3)]==[0,1,1]
        max(i,2)=y(3);
    end
    
    if [temp(i,1),temp(i,2),temp(i,3)]==[0,1,0]
        max(i,2)=y(4);
    end
    
    if [temp(i,1),temp(i,2),temp(i,3)]==[1,1,0]
        max(i,2)=y(5);
    end
    
    if [temp(i,1),temp(i,2),temp(i,3)]==[1,1,1]
        max(i,2)=y(6);
    end
    
    if [temp(i,1),temp(i,2),temp(i,3)]==[1,0,1]
        max(i,2)=y(7);
    end
    
    if [temp(i,1),temp(i,2),temp(i,3)]==[1,0,0]
        max(i,2)=y(8);
    end
end

%%% X-coordinate --------------------------
for i=1:K
    if [temp(i,4),temp(i,5),temp(i,6)]==[0,0,0]
        max(i,1)=x(1);
    end
    
    if [temp(i,4),temp(i,5),temp(i,6)]==[0,0,1]
        max(i,1)=x(2);
    end
    
    if [temp(i,4),temp(i,5),temp(i,6)]==[0,1,1]
        max(i,1)=x(3);
    end
    
    if [temp(i,4),temp(i,5),temp(i,6)]==[0,1,0]
        max(i,1)=x(4);
    end
    
    if [temp(i,4),temp(i,5),temp(i,6)]==[1,1,0]
        max(i,1)=x(5);
    end
    
    if [temp(i,4),temp(i,5),temp(i,6)]==[1,1,1]
        max(i,1)=x(6);
    end
    
    if [temp(i,4),temp(i,5),temp(i,6)]==[1,0,1]
        max(i,1)=x(7);
    end
    
    if [temp(i,4),temp(i,5),temp(i,6)]==[1,0,0]
        max(i,1)=x(8);
    end
end


clear i;
clear k;
clear temp;



for i=1:K
    p_out(i,:)=max(i,1)+max(i,2)*j;   %%% generate complex constellations,and parallel sequence
end
clear max;

out=p_out;     %%% parallel complex constellations

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?