%%16QAM
%%等效基带调制
clc;
clear all;
close all;%%关闭所有窗口,比如之前画的图
nsymbol = 10000;%%每种信噪比下符号数的发送符号数,10^6个数
errornumber = zeros(1,10);
errorratio = zeros(1,10);
data = randi([0,1],1,4*nsymbol);%%产生1行,4*nsymbol列均匀分布的随
机数
data_ mod1 = zeros(1,nsymbol);%%各参量初始化
data_ mod2 = zeros(1,nsymbol);
data_demod1 = zeros(1,nsymbol);
data_demod2 = zeros(1,nsymbol);
data_demod3 = zeros(1,nsymbol);
data_demod4 = zeros(1,nsymbol);
s_ receive1 = zeros(1,nsymbol);
s_ receive2 = zeros(1,nsymbol);
for i = 1:nsymbol %%格雷码调制到星座图的映射
if data(4*i-3)==0 && data(4*i-2)==0
data_ mod1(i) = 3;
if data(4*i-1)==0 && data(4*i)==0
data_ mod2(i) = 3;
elseif data(4*i-1)==0 && data(4*i)==1
data_ mod2(i) = 1;
elseif data(4*i-1)==1 && data(4*i)==1
data_ mod2(i) = -1;
elseif data(4*i-1)==1 && data(4*i)==0
data_ mod2(i) = -3;
end
elseif data(4*i-3)==0 && data(4*i-2)==1
data_ mod1(i) = 1;
if data(4*i-1)==0 && data(4*i)==0
data_ mod2(i) = 3;
elseif data(4*i-1)==0 && data(4*i)==1
data_ mod2(i) = 1;
elseif data(4*i-1)==1 && data(4*i)==1
data_ mod2(i) = -1;
elseif data(4*i-1)==1 && data(4*i)==0
data_ mod2(i) = -3;
end
elseif data(4*i-3)==1 && data(4*i-2)==1
data_ mod1(i) = -1;
if data(4*i-1)==0 && data(4*i)==0
data_ mod2(i) = 3;
elseif data(4*i-1)==0 && data(4*i)==1
data_ mod2(i) = 1;
elseif data(4*i-1)==1 && data(4*i)==1
data_ mod2(i) = -1;
elseif data(4*i-1)==1 && data(4*i)==0
data_ mod2(i) = -3;
end
elseif data(4*i-3)==1 && data(4*i-2)==0
data_ mod1(i) = -3;
if data(4*i-1)==0 && data(4*i)==0
data_ mod2(i) = 3;
elseif data(4*i-1)==0 && data(4*i)==1
data_ mod2(i) = 1;
elseif data(4