16qam理论误码率与实际误码率matlab仿真程序.docx
%%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 if data(4*i-1)==0 elseif data(4*i-1)==0 elseif data(4*i-1)==1 elseif data(4*i-1)==1 endelseif data(4*i-3)==0 if data(4*i-1)==0 elseif data(4*i-1)==0 elseif data(4*i-1)==1 elseif data(4*i-1)==1 endelseif data(4*i-3)==1 if data(4*i-1)==0 elseif data(4*i-1)==0 elseif data(4*i-1)==1 elseif data(4*i-1)==1 endelseif data(4*i-3)==1 if data(4*i-1)==0 elseif data(4*i-1)==0 elseif data(4*i-1)==1 elseif data(4*i-1)==1 endendend SNR_dB = 1:10;%%% 信噪比 dB 形式 SNR = 10.^(SNR_dB/10);%% 信噪比转化为线性值 for loop= 1:10sigma = sqrt(5/SNR(loop));s_receive1 = data_mod1 + sigma * randn(1,length(data_mod1));s_receive2 = data_mod2 + sigma * randn(1,length(data_mod2));%%??for k = 1:nsymbolif s_receive1(k)>2 data_demod1(k) = 0;data_demod2(k) = 0;if s_receive2(k)>2data_demod3(k) = 0;data_demod4(k) = 0;elseif s_receive2(k)>0 data_demod4(k) = 0;elseif s_receive2(k)>0 data_demod2(k) = 1;if s_receive2(k)>2data_demod3(k) = 0;data_demod4(k) = 0;elseif s_receive2(k)>0 data_demod4(k) = 0;elseif s_receive2(k)>0 && s_receive2(k)-2 && s_receive2(k)<0